The api my app is working with is expecting a GET request for search results that looks like this:
Method: GET
Headers:
{
"Content-Type": "application/json",
"X-AUTHORIZATION": "8eb40dba2f0c6d7de8b9c6e1865aa507"
}
Request:
{
"keyword": "X S"
}
Response:
{
"status": "success",
"code": 0,
"meta": {
"exec_time": 0.012183904647827
},
"message": "",
"data": [
]
}
I have a class called HttpGetWithEntity
that i found online that looks like this:
public class HttpGetWithEntity extends HttpEntityEnclosingRequestBase {
public HttpGetWithEntity() {
super();
}
public HttpGetWithEntity(URI uri) {
super();
setURI(uri);
}
public HttpGetWithEntity(String uri) {
super();
setURI(URI.create(uri));
}
@Override
public String getMethod() {
return HttpGet.METHOD_NAME;
}
}
and i am implementing it like so:
public HttpResponse invokeXAUTHGETJsonService(String url, String token,
String jsonPost) {
Log.v("KEYWORD", "KEYWORD GOING UP:"+jsonPost);
HttpParams params = new BasicHttpParams();
HttpResponse response = null;
try {
HttpGetWithEntity request = new HttpGetWithEntity(url);
Log.v("UPU", "URL:" + url +" token:"+token);
request.setHeader("X-AUTHORIZATION", token);
request.setHeader("Accept", "application/json");
request.addHeader("Content-Type", "application/json");
StringEntity se = new StringEntity(jsonPost);
request.setEntity(se);
response = client.execute(request);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return response;
}
My log to check the json i am posting looks like this:
03-09 14:38:01.034: V/KEYWORD(11739): KEYWORD CREATED: {"keyword":"e"}
The problem is, it seems like the JSON never reaches the api or is ignored. Does anyone know what i am doing wrong..
thanks