I'm sending a Json message to an API, i'm getting an error but I want to know what I'm sending to the API. By the way the authentification method is by token access.
The method is this one:
public static void sendRequestPost2(JSONObject json) throws IOException, JSONException {
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
try {
HttpPost request = new HttpPost(Config.urlJSON);
StringEntity params = new StringEntity(json.toString());
request.addHeader("Authorization", "Token " + Config.renamToken);
request.addHeader("content-type", "application/json");
request.setEntity(params);
int statusCode = httpClient.execute(request).getStatusLine().getStatusCode();
Log.debug("[STATUS:" + statusCode + "]");
} catch (Exception ex) {
Log.debug(ex.toString());
} finally {
httpClient.close();
}
}
I have tried several gets of the request object but I'm getting the results separately:
request.setEntity(params);
Log.debug(request.getMethod());
Header[] heads = request.getAllHeaders();
String headsString = "";
for (int i = 0; i < heads.length; i++) {
headsString += heads[i];
}
String entity = EntityUtils.toString(request.getEntity());
Log.debug(entity);
Log.debug(request.getRequestLine().toString());
Log.debug(headsString);
Log.debug(request.getURI().toURL().toString());
CloseableHttpResponse response = httpClient.execute(request);
Log.debug(response.getStatusLine().toString());
String content = EntityUtils.toString(response.getEntity());
Log.debug(content);
I can get a lot of information but I'm not getting the full string before send it to the API and I need to know if the string is correct.
Thank you.