我想从Android应用程序将数据发送到服务器(.NET),但它不工作,这是我的代码:如何将数据从我的android应用程序发布到服务器?
DefaultHttpClient hc=new DefaultHttpClient();
ResponseHandler <String> res=new BasicResponseHandler();
HttpPost postMethod=new HttpPost(myURl);
postMethod.getParams().setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE);
postMethod.getParams().setBooleanParameter("http.protocol.expect-continue", false);
postMethod.setHeader("Content-Type", "application/json");
JSONObject json = new JSONObject();
json.put("TOKEN", channel_token).toString();
json.put("APPLICATIONDATASOURCEID", data_src_id).toString();
json.put("NEWSTITLE", Title_edittext.getText().toString().trim()).toString();
json.put("NEWSDETAILS", Details_edittext.getText().toString()).toString();
json.put("ALERTSTARTSAT" , "12/03/2012/05/12");
json.put("ALERTENDSAT", "13/03/2012/06/12");
json.put("SENDPUSHNOTIFICATION", true);
json.put("EXPIREIMMEDIATELY", true);
Log.i("jason Object", json.toString());
StringEntity se = new StringEntity(json.toString());
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"application/json"));
postMethod.setEntity(se);
HttpResponse response = hc.execute(postMethod);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
String _response = convertStreamToString(is);
System.out.println("res " + _response);
得到这个从服务器响应“Expectaions失败”。请告诉我问题在哪里。
你在json字符串中传递正确的参数吗?什么是你的StatusCode? – waqaslam 2012-02-28 09:20:43
参数是否正确,状态码的含义。 – 2012-02-28 09:28:12
try postMethod.getParams()。setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE,Boolean.TRUE); – 2012-02-28 09:37:46