1
我是新的android.Currently我在做web服务连接部分在android.Here我使用httpdelete method.But我无法发送值到server.Here我附加我的code.please给我一个解决方案。传递JSON对象如下。使用httpdelete发送数据到服务器
JSONObject obj = {"encrypted_device_id":"c02c705e98588f724ca046ac59cafece65501e36","card_name":"disc"}
CODE
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行httppost.setEntity(se); 。我做了那一个,但在当时一些HTML是从服务器返回 –