【问题标题】:How to delete data with httpDelete via JSON如何通过 JSON 使用 httpDelete 删除数据
【发布时间】:2014-03-12 03:10:41
【问题描述】:

如何删除 http 数据库中的某一行?我正在考虑像 httpGet 一样使用 httpDelete,但它不起作用。

这是我的发布和删除代码。我很担心通过使用 deleteMarkerData(),我删除了整个表,而不仅仅是一个表。

public void postCarData() {
    Thread t = new Thread() {
        public void run() {
            HttpClient client = new DefaultHttpClient();
            HttpPost post = new HttpPost( CAR_URI);
            try {
              List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(5);
              nameValuePairs.add(new BasicNameValuePair("name", String.valueOf(lat)));
              nameValuePairs.add(new BasicNameValuePair("description", ""));
              nameValuePairs.add(new BasicNameValuePair("price", String.valueOf(lon)));
              nameValuePairs.add(new BasicNameValuePair("product", UserLogin.accountName ));
              nameValuePairs.add(new BasicNameValuePair("action", "put"));
              post.setEntity(new UrlEncodedFormEntity(nameValuePairs));

              HttpResponse response = client.execute(post);
              BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
              String line = "";
              while ((line = rd.readLine()) != null) {    Log.d(TAG, line);       }
            } catch (IOException e) {   Log.d(TAG, "IOException while trying to conect to GAE"); }
        }
    };
    t.start();
}

public void deleteCarData() throws ClientProtocolException, IOException {
    HttpClient client = new DefaultHttpClient();
    HttpDelete delete = new HttpDelete( CAR_URI );
    client.execute(delete);
}

【问题讨论】:

    标签: android json http


    【解决方案1】:

    您问的是为什么服务器的 DELETE 方法的行为如此,而您发布了一个问题,其中包含 DELETE 方法的客户端的代码。如果不知道 CAR_URI 背后的服务器是做什么的,就无法回答这个问题

    【讨论】:

      猜你喜欢
      • 2021-05-08
      • 2018-01-24
      • 2018-11-28
      • 2014-11-05
      • 1970-01-01
      • 2017-10-24
      • 1970-01-01
      • 2020-08-25
      • 2016-12-18
      相关资源
      最近更新 更多