【发布时间】:2014-03-01 12:33:57
【问题描述】:
我是 android 的新手。目前我正在 android 中做 web 服务连接部分。这里我使用 httpdelete 方法。但我无法将值发送到服务器。这里我附上我的代码。请给我一个解决方案。传递的 JSON 对象如下所示。
JSONObject obj = {"encrypted_device_id":"c02c705e98588f724ca046ac59cafece65501e36","card_name":"disc"}
代码
public String getWebDataDelete(String page,JSONObject obj)
{
String result=null;
HttpParams myParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(myParams, 10000);
HttpConnectionParams.setSoTimeout(myParams, 10000);
HttpClient httpclient = new DefaultHttpClient(myParams);
try
{
HttpDelete httppost = new HttpDelete(Connector.URL+page);
httppost.setHeader("Content-type", "application/json");
httppost.setHeader("api_key", "123456");
StringEntity se = new StringEntity(obj.toString());
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
httppost.setEntity(se);
HttpResponse response = httpclient.execute(httppost);
result = EntityUtils.toString(response.getEntity());
}
catch (ClientProtocolException e)
{
}
catch (IOException e)
{
}
return result;
}
【问题讨论】:
-
您遇到错误了吗?如果是,请发布它
-
嗨,我在 httppost.setEntity(se) 行中添加了 httppost; .我做了那个,但当时一些 html 从服务器返回
标签: android web-services http-delete