我尝试从我的Android设备连接到REST Web服务,并在其中放置一些数据,但是我得到的只是GET结果。甚至我的网络服务器都坚持这是一个GET请求。我的代码有什么问题?

DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPut httpPut = new HttpPut(url);
httpPut.addHeader("Content-Type", "application/xml; charset=utf-8");
httpPut.addHeader("User-Agent", "Android");
HttpEntity entity = new StringEntity(data);
httpPut.setEntity(entity);
HttpResponse response = httpclient.execute(httpPut);
HttpEntity input = response.getEntity();
StringBuilder result = new StringBuilder();
if (input != null) {
    InputStream instream = input.getContent();
    result = convertStreamToString(instream);
    instream.close();
}
httpclient.getConnectionManager().shutdown();
return result.toString();

最佳答案

试听

Android HttpPut example code

 为什么使用put方法而不发布?

09-29 22:38