cannot print the Json-RPC Response
سؤال
I have a java webservice, that must return a response if the login is successful
The return line of the server side method is
return new Response(new InfoSessionJson(newKey, is), null, id);
To get the response I have tried to use the code
HttpResponse response = mClient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
if(response != null){
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
loggato=true;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
System.out.println("The response is "+sb.toString());
But the output print returns an apache error
I have tried to print the output of the
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
directly with
System.out.print(entity);
System.out.print(response);
and this print:
org.apache.http.conn.BasicManagedEntity@40575ac8 org.apache.http.message.BasicHttpResponse@40574a00
Where is the error??
I cannot parse the response correctly or the problem is before???
the webservice method has this fim
@Webservice(paramNames = {"email", "password", "stayLogged", "idClient"},
public Response startSession(String email, String password, Boolean stayLogged, String idClient)
and I send a json with
StringEntity stringEntity = new StringEntity(jsonObject.toString());
httpost.setEntity(stringEntity);
httpost.setHeader("Accept", "application/json");
httpost.setHeader("Content-type", "application/json");
Where the json object sent is
{"method":"startSession","params":[{"email":"test.web@yahoo.it","password":"1234","idClient":"ANDROID","stayLogged":"1"}]}
The webservice works fine with an iOS app but wont work with mine android app,
Where is the error in the procedure that I have described in this thread???
I hope someone can help me.
المحلول
I should use the code
stringEntity.setContentEncoding(HTTP.UTF_8);
to set the encoding mode to UTF, with this, the server accept the json request and give the correct response
نصائح أخرى
Try: System.out.println("The response is "+sb.toString());
.
line
is erased at each loop.
I have almost the exact same code and it works fine for me, maybe there is a issue with the request that you are sending. Look at the response status code to check for errors:
status = response.getStatusLine();
status_code = status.getStatusCode();
There may be some error on the server side causing you to get an empty 500 response or something.