【发布时间】:2014-05-19 06:42:50
【问题描述】:
我遇到了这个问题,我需要将数据放入或修补到服务器。我知道如何做一个标准的帖子,但我怎么能做这个 PATCH 或 PUT 到服务器?
服务器的URL是PATCH to www.example.com/api/documents,参数是doc_id(integer)。
这是我目前拥有的
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("content-type", "application/json");
httpPost.setHeader("accept-charset", "utf8");
try {
HttpResponse response = httpClient.execute(httpPost);
responseString = EntityUtils.toString(response.getEntity());
} catch (Exception e) {
Log.e("Request exception:", "excpetion", e);
}
return responseString;
但是我认为这段代码是错误的:)
【问题讨论】:
-
这是 http POST 而不是 PUT。
-
@VedPrakash 我知道 - 你能告诉我如何对服务器执行 PUT 或 PATCH 操作吗?
标签: java android androidhttpclient