【发布时间】:2014-03-09 18:31:25
【问题描述】:
我的应用正在使用的 api 需要一个对搜索结果的 GET 请求,如下所示:
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": [
]
}
我有一个名为HttpGetWithEntity 的课程,我在网上找到它,看起来像这样:
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;
}
}
我是这样实现的:
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;
}
我检查我发布的 json 的日志如下所示:
03-09 14:38:01.034: V/KEYWORD(11739): KEYWORD Created: {"keyword":"e"}
问题是,似乎 JSON 从未到达 api 或被忽略。有谁知道我做错了什么..
谢谢
【问题讨论】: