【发布时间】:2014-02-26 18:05:07
【问题描述】:
我正在尝试将数据发布到this 网络服务,但我似乎无法做到这一点!所以我试图将 json 发布到服务器,但我不知道该怎么做。我需要发送这个示例 json 以获得 json 响应:
内容类型:应用程序/json HTTPMethod:POST HTTPBody: { “CouponVerificationCode”: “594952223490”, “ApiKey”: “zFyWQDYUKXQQpvG86snPD1OSslr7Q6DGEGbQ1f7P2YeTxB56y”, “标记”: “_ 2_jx1YFvTZGGLNtJBoDW3gDZmNNAGpTWzT7dC6GrNAIkhhX9PWv75b776gq1ZO_2_SxMJjq8_2_kaDMyxX59HczOyaw ==”} P>
但我没有得到 json 响应,而是得到了 html 响应。 有人可以帮我解决这个问题吗?
这是我用来与服务器通信的代码:
public static String makeRequest(String path) throws Exception {
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost(path);
JSONObject holder = new JSONObject();
// holder.accumulate(name, value)
String test = "{\"ApiKey\":\"somekey\","
+ "\"OperativeSystem\":\"0\","
+ "\"AppVersion\":\"1\","
+ "\"WebServiceVersion\":\"1\"}";
StringEntity se = new StringEntity(test);
Log.v("--", test);
httpost.setEntity(se);
httpost.setHeader("Accept", "application/json");
httpost.setHeader("Content-type", "application/json");
ResponseHandler responseHandler = new BasicResponseHandler();
String response = httpclient.execute(httpost, responseHandler);
// HttpEntity entity = response.getEntity();
Log.v("--", response);
return response;
}
【问题讨论】:
-
需要解析responce转换成字符串
-
@geekCode 响应是 html 而不是 json
-
你现在得到的答案是什么..??
-
@DarkoPetkovski - 您需要确认以下组合 url 、请求类型、请求内容类型。如果其中一个不正确,您将无法正确访问网络服务。
-
而且也没有发布数据...
标签: android json web-services android-json android-webservice