Android 使用httpdelete将数据发送到服务器

Android 使用httpdelete将数据发送到服务器,android,web-services,http-delete,Android,Web Services,Http Delete,我是android新手。目前我正在android中做web服务连接部分。这里我使用httpdelete方法。但是我无法将值发送到服务器。这里我附加了我的代码。请给我一个解决方案。下面给出了传递的JSON对象 JSONObject obj = {"encrypted_device_id":"c02c705e98588f724ca046ac59cafece65501e36","card_name":"disc"} 代码 public String getWebDataDelete(String p

我是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的添加cast。我这样做了,但在从服务器返回一些html时,我需要httpdelete方法notpost
  Try this one, working for me


  DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpPost request = new HttpPost(Url);
        StringEntity se = new StringEntity(JSONobject.toString(), "UTF-8");
        se.setContentType("application/json;charset=UTF-8");
        se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
                "application/json;charset=UTF-8"));
        request.setEntity(se);
        HttpResponse httpresponse = httpclient.execute(request);
        HttpEntity resultentity = httpresponse.getEntity();
        InputStream inputstream = resultentity.getContent();
        result = convertStreamToString(inputstream);


  private static String convertStreamToString(InputStream inputstream) {
    // TODO Auto-generated method stub
    String line = "";
    StringBuilder total = new StringBuilder();
    BufferedReader rd = new BufferedReader(new InputStreamReader(
            inputstream));
    try {
        while ((line = rd.readLine()) != null) {
            total.append(line);
        }
    } catch (Exception e) {
    }
    return total.toString();
}