Hi.
I’m trying to implement a java client to request message creation, using rest-api.
The response is 400, Bad Request.
Please, help!!!
This is the java code:
[lua]
String contents = "{ " +
"“app_id” : “xxxxx”, " +
""contents : {“en” : “Java test”}, " +
"“isAndroid” : true, " +
"“url” : “http://www.google.es”, " +
"“included_segments” : [“All”] " +
“}”;
String url = “https://gamethrive.com/api/v1/notifications”;
String method = “POST”;
String contentType = “application/json”;
URL u = new URL(url);
HttpURLConnection conn = (HttpURLConnection)u.openConnection();
conn.setRequestMethod(method);
conn.setRequestProperty(“Content-Type”, contentType);
conn.setRequestProperty(“Content-Length”, “”+contents.length());
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestProperty(“Authorization”, "Basic " + “xxxxx”);
OutputStream os = conn.getOutputStream();
DataOutputStream wr = new DataOutputStream(os);
wr.writeBytes (contents);
wr.flush ();
wr.close ();
InputStream is = conn.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
StringBuffer response = new StringBuffer();
while((line = rd.readLine()) != null) {
response.append(line);
response.append(’\r’);
}
rd.close();
[/lua]