我有以下代码,我正在尝试将数据发布到网络服务。但我得到的响应是 {"Message":"An Error Has Occured"}。我不知道我错在哪里。请仔细阅读代码并告诉我。
@Override
protected String doInBackground(String... urls) {
HttpClient httpClient= new DefaultHttpClient();
HttpContext context=new BasicHttpContext();
HttpPost httpPost=new HttpPost(url);
JSONObject json=new JSONObject();
httpPost.setHeader("Content-type",
"application/json; charset=UTF-8");
try {
json.put("EmailID","test@yahoo.com");
json.put("ProjID","78");
json.put("Uid","1");
StringEntity stringEntity = new StringEntity(json.toString());
InputStream stream= new ByteArrayInputStream(json.toString().getBytes("UTF-8"));
httpPost.setEntity(new StringEntity(json.toString()));
HttpResponse httpResponse= httpClient.execute(httpPost,context);
BufferedReader reader= new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(),"UTF-8"));
res= reader.readLine();
resp=res.toString();
Log.e("RESPONSE OF WEBSER:", resp);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return resp;
这是jsonobject。
jsonObjects = {
"ProjID": "78",
"Uid": "1",
"EmailID": "test@yahoo.com",
"ProjectInviterFQAnswer": [{
"slno": "1",
"Answer": "a1",
"order": "1",
"flag": "F"
}, {
"slno": "2",
"Answer": "a1",
"order": "2",
"flag": "F"
}, {
"slno": "1",
"Answer": "a1",
"order": "2",
"flag": "Q"
}
]
};
现在我想把我的价值观放在“答案”键中。但我得到的响应是 {"Message":"An Error Has Occured"}
等待适当的解决方案。谢谢你。