0
我试图发布数据到this web服务,但似乎我不能得到这个权利!所以我试图发布json到服务器,但我不知道该怎么做。我需要为了得到一个JSON性反应的发这个例子JSON:将数据发送到服务器并处理响应 - Android电子
内容类型:应用程序/ JSON列举HTTPMethod:POST HTTPBody: { “CouponVerificationCode”: “594952223490”, “ApiKey”: “zFyWQDYUKXQQpvG86snPD1OSslr7Q6DGEGbQ1f7P2YeTxB56y” “令牌”: “_ 2_jx1YFvTZGGLNtJBoDW3gDZmNNAGpTWzT7dC6GrNAIkhhX9PWv75b776gq1ZO_2_SxMJjq8_2_kaDMyxX59HczOyaw ==”}
而不是让一个JSON性反应,我得到的html性反应,但。 是否有人可以帮我解决这个问题?
这是使用与服务器通信代码IM:
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;
}
您需要解析性反应将其转换为字符串 – geekCode
@geekCode的性反应是HTML不是JSON –
,答案是什么你现在越来越..? – geekCode