I am using this code to send a request from Android to a Spring server. The method in Spring must return a String, but doesnt works:
idstringtoparse=CustomHttpClient.executeHttpPost(urlGetUserIdByUsername, params);
Being the method executeHttpPost this way:
public static String executeHttpPost(String url, ArrayList<NameValuePair> postParameters) throws Exception {
BufferedReader in = null;
try{
HttpClient client = getHttpClient();
HttpPost request = new HttpPost(url);
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters,"UTF-8");
formEntity.setContentEncoding(HTTP.UTF_8);
request.setEntity(formEntity);
request.setHeader("Content-Type",
"application/x-www-form-urlencoded;charset=UTF-8");
HttpResponse response = client.execute(request);
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
String result = sb.toString();
return result;
}
}
In the server, the code is like this:
@RequestMapping ("usuario/getIdUserByUsername")
@ResponseBody
public Long getUserIdByUsername(@RequestParam String username){
Long id=(long)usuarioService.getUserIdByUsername(username);
usuarioService.getUserIdByUsername(username);
return id;
}
This way, I am receiving a 406 error saying "The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers"
Its a bit strange, since I am using that very same method in my app before this point to log ing the server, and it is working perfectly.
Aucun commentaire:
Enregistrer un commentaire