HttpDelete 是否包含 setEntity() 等方法,如 HttpPost 或 HttpPut?
当我使用 HttpPost 时,我会做这样的事情:
httppost.setEntity(new UrlEncodedFormEntity(
getNameValuePairsForFriends(context, friendID)));
我怎样才能通过删除来做到这一点?
class MyDelete extends HttpPost
{
public MyDelete(String url){
super(url);
}
@Override
public String getMethod() {
return "DELETE";
}
}
让你的类在那里扩展http删除类,并在你的类的对象发送实体期间,你将能够在httpdelete中发布数据
HttpResponse httpResponse;
String result = null;
HttpClient httpClient = new DefaultHttpClient();
HttpConnectionParams
.setConnectionTimeout(httpClient.getParams(), 10000);
MyDelete httpDelete = new MyDelete(urlUnfollowPatientBundle);
StringEntity entity = null;
try {
entity = new StringEntity(rawData);
httpDelete.setEntity(entity);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
try {
httpResponse = httpClient.execute(httpDelete);
if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
HttpEntity httpEntity = httpResponse.getEntity();
result = EntityUtils.toString(httpEntity);
status = true;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)