Archived Forum Post

Index of archived forum posts

Question:

CkHttp - setEntity

Jan 22 '13 at 09:18

Hello!

I'm using the chilkat android library, and wonder if it is possible to set an Entity to the CkHttp object. In pure Java it's done this way:

HttpPost post = new HttpPost(urlString);
HttpResponse response;
StringEntity se = new StringEntity(newStringFromBytes);
post.setEntity(se);
response = httpClient.execute(post);

I've tried with the PostJSON method:

JSONObject jObject = new JSONObject();
jObject.put("encodedData", newStringFromBytes);
resp = http.PostJson(urlString, jObject.toString());

But the webservice I try to contact won't accept this, and returns a HTTP 1.1/500 Internal Server Error.

I could of course used the "standard java way", but there are some neat functionality in the Chilkat library I will use in the future, regarding posting over HTTPS

Thanks in advance!


Answer

The term "entity" is a Java made-up term that corresponds to some part of the HTTP request. I don't know exactly what it is, but my guess is that it's simply the body of the MIME (i.e. everything that comes after the MIME header of the request).

Therefore, it should already be possible with Chilkat -- it's just a matter of figuring out how to get the HTTP request you desire.

My advice would be to set the http.SessionLogFilename property so that the Chilkat HTTP object logs the exact HTTP requests and responses to a file. You can then examine the file to see how the HTTP request is different than what you actually need. Feel free to post the session log information here, pointing out the part(s) of the request that do not conform to what is desired.