- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试用这个删除一个参数:
private class SendfeedbackDeleteStudio extends AsyncTask<String, Void, String> {
private static final String LOG_TAG = "DeleteStudio";
Bundle extras = getIntent().getExtras();
final String token= extras.getString("TOKEN");
@Override
protected String doInBackground(String... params) {
String venid = params[0];
Utils.log("venid: " + venid);
final String url_delete_studio = Constant.URI_BASE_FAVOURITE;
String contentType;
contentType = "application/x-www-form-urlencoded";
// do above Server call here
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(1);
nameValuePair.add(new BasicNameValuePair("vendor_id", venid));
try
{
HttpClient httpClient = new DefaultHttpClient();
HttpDelete httpDelete = new HttpDelete(url_delete_studio);
httpDelete.setHeader("Content-Type", contentType);
httpDelete.setHeader("Authorization", "Bearer " + token);
httpDelete.setHeader("Accept", "application/json");
httpDelete.setHeader("Accept-Charset", "utf-8");
httpDelete.setEntity(new UrlEncodedFormEntity(nameValuePair));
HttpResponse response = httpClient.execute(httpDelete);
HttpEntity entity = response.getEntity();
if (entity != null) {
// EntityUtils to get the reponse content
String content = EntityUtils.toString(entity);
Utils.log("daftar content: " + content);
JSONObject hasiljson = new JSONObject(content);
Utils.log("hasiljson object: " + hasiljson);
String success = hasiljson.getString("success");
Utils.log("success: " + success);
}
// writing response to log
Log.d("Http Response:", response.toString());
}
catch (Exception e)
{
Log.e(LOG_TAG, String.format("Error during delete: %s", e.getMessage()));
}
return "processing";
}
@Override
protected void onPostExecute(String message) {
//process message
clickFavourites();
}
}
但是它在 httpDelete.setEntity(new UrlEncodedFormEntity(nameValuePair)); 上变红了,它似乎无法识别我发送给 delete 的参数。如何删除venid参数?
最佳答案
HTTP DELETE 的行为类似于 GET 变体,因此它不会接受任何输入。
如果您希望提供带有正文的删除,您可能需要考虑对接受正文的位置使用 POST。
或者你可以使用这个
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import java.net.URI;
import org.apache.http.annotation.NotThreadSafe;
@NotThreadSafe
class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase {
public static final String METHOD_NAME = "DELETE";
public String getMethod() { return METHOD_NAME; }
public HttpDeleteWithBody(final String uri) {
super();
setURI(URI.create(uri));
}
public HttpDeleteWithBody(final URI uri) {
super();
setURI(uri);
}
public HttpDeleteWithBody() { super(); }
}
引用自here
关于java - HttpDelete 参数与 setEntity 在 android 上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33911438/
创建了一个 ASP.NET Core Web API。使用以下代码,我可以使用 body 中的 Id 从 Postman 执行删除。 [Authorize] [Produces("applic
我正在尝试使用 HttpDelete 对象来调用 Web 服务的删除方法。 Web 服务的代码从消息的正文中解析 JSON。但是,我不明白如何将正文添加到 HttpDelete 对象。有没有办法做到这
我有一个像这样的 Controller (我将发布所有代码,以便您可以看到它是如何工作的)。 /// /// Handles all of the Upload functions, includi
HttpDelete 是否包含 setEntity()、HttpPost 或 HttpPut 之类的方法?当我使用 HttpPost 时,我会做这样的事情: httppost.setEntity(ne
我有一个只有一个 View 的 ProductsController - Index.cshtml。 此 Controller 内部有以下 3 个操作方法: //http://localhost:55
我需要向服务器发送一个 ID,并让服务器删除数据库中的一条记录。我想使用HttpDelete Apache Android SDK 集成类,但我不知道如何使用它以及如何将参数传递给服务器。对于 POS
您好,我是 Apache http 客户端的新手,您能帮助我吗? 我有下一个参数 {“名字”:“悟空”} 我发送此参数以将其删除。 请帮助我 最佳答案 可以在此处找到 Apache Http 基础知识
我正在尝试通过 jQuery 向 Controller 执行删除请求。在本地它可以工作,但是当部署到服务器时我收到 501 状态。 我已经确认,对于 .cshtml,所有动词都被接受,并且不需要文件验
我尝试用这个删除一个参数: private class SendfeedbackDeleteStudio extends AsyncTask { private static final St
我需要调用网络服务来删除数据,我需要使用 HttpDelete 来完成。该服务将 JSON 对象作为参数。 我之前使用 SetEntity 完成了 HttpPost,但这不适用于 HttpDelete
我正在尝试学习如何操作 scala 和 key-value etcd。我知道如何发布和从中获取数据。至少整个 key 。在这种情况下,整个“testDistrict”及其包含的所有内容。但我不知道如何
我有 API Controller ,方法是: [Route("campaigns")] [HttpDelete] public async Task Delete(strin
您好,我已经编写了一个删除多个文件的休息服务,我正在尝试访问休息服务。我对休息服务的输入将是列表值,这将是需要删除的文件的 ID。为此,我编写了以下代码 List ids=new ArrayL
当我单击模板列中的删除按钮时,我收到内置警告警报,显示“您确定要删除此记录吗?”这让我知道我正在正确触发网格的内置销毁功能。通过调用: grid.removeRow(row); 但是,当我在警报窗口中
我正在尝试通过删除链接(href)或删除按钮(表单)删除页面上的实体。我正在使用删除按钮,因为链接需要“GET”而不是“POST” 这是打算这样做的 JSP 代码: 生成的 html 是这样的:
在调用接受删除动词的 Controller 操作时,我遇到了一个现在允许异常的方法。 我认为问题是 IIS 7.0 中的 HandlerMappings 错误,当我查看时在: Extensionles
我有一个 HTTP DELETE 方法的终点。我想传递一些 header ,更具体地说是 Content-Type=application/x-www-form-urlencoded。还有一些参数,在
我正在尝试在 ASP.NET MVC 中创建一个 api。不幸的是,我遇到了两个 HTTP 请求的问题:DELETE 和 PUT [ActionName("Index")] [Http
这可能吗? 代码看起来像这样...... [Transaction] [ValidateAntiForgeryToken] [HttpDelete] public ActionResult Delet
我无法访问此方法: [HttpPut] [Route("api/Order/Update/{id}")] public async Task UpdateList([FromBody]OrderVie
我是一名优秀的程序员,十分优秀!