我可以在Python Windows SDK中使用此动词.但不是在生产中.为什么?我究竟做错了什么?
错误消息包括(仅通过firebug或fiddler看到)
格式错误的请求
或类似的东西
我的代码看起来像:
from google.appengine.ext import db
from google.appengine.ext import webapp
class Handler(webapp.RequestHandler):
def delete(self):
key = self.request.get('key')
item = db.get(key)
item.delete()
self.response.out.write(key)
Run Code Online (Sandbox Code Playgroud) 我向服务器发送删除请求,如:
@RequestMapping(value = "/user/{userId}", method = RequestMethod.DELETE)
Run Code Online (Sandbox Code Playgroud)
对于单个用户删除.但是,当多个用户想要删除时该怎么办?我想遵守REST架构,但我想看到发送多个删除请求的另一种方法?
PS:这是一个合适的方式:
@RequestMapping(value = "/user", method = RequestMethod.DELETE, headers = "Accept=application/json")
public void deleteUser(HttpServletResponse response, @RequestBody String users) throws IOException {
...
}
Run Code Online (Sandbox Code Playgroud) 我的用户已经对我的LinkedIn应用程序进行了身份验证,但我也想让他们在任何给定时间从我的应用程序中取消身份验证.
我想我只是错过了http删除网址,但我不确定.
谢谢
Spring @CrossOrigin 注释不适用于 DELETE 方法。
示例代码(在 Groovy 中):
@CrossOrigin
@RestController
@RequestMapping('/rest')
class SpringController {
@RequestMapping(value = '/{fileName}', RequestMethod.DELETE)
void deleteFile(@PathVariable fileName) {
// logic
}
}
Run Code Online (Sandbox Code Playgroud)
对于这段代码,我得到了异常:
XMLHttpRequest 无法加载http://localhost:8080/rest/filename.txt。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许访问Origin ' http://localhost:4200 '。响应具有 HTTP 状态代码 404。
笔记:
@CrossOrigin(methods =
[RequestMethod.GET, RequestMethod.DELETE])
没有帮助我正在尝试做的事情:尝试使用"正确的"HTTP删除删除记录.
控制器代码:
[HttpDelete]
public void DeleteRun(int RunId)
{
repository.RemoveEntry(RunId);
}
Run Code Online (Sandbox Code Playgroud)
剃刀查看:
@Ajax.ActionLink("Delete","DeleteRun",new {RunId = run.RunId},
new AjaxOptions() { Confirm = "Are you sure you want to delete this entry?",
HttpMethod = "DELETE",
OnComplete = string.Format("DeleteRunInTable({0})",run.RunId)
})
Run Code Online (Sandbox Code Playgroud)
Javascript(在单独的包含文件中):
function DeleteRunInTable(RunId) {
$("tr[data-runid=" + RunId).remove();
}
Run Code Online (Sandbox Code Playgroud)
链接actionlink方法正在创建:
<a data-ajax="true" data-ajax-complete="DeleteRunInTable(11)" data-ajax-confirm="Are you sure you want to delete this entry?" data-ajax-method="DELETE" href="/Runs/Delete/11">Delete</a>
Run Code Online (Sandbox Code Playgroud)
不确定javascript部分是否有效但不担心它.试着一次迈出一步:).现在它只是像传统标签一样工作,当我点击链接时它只是做一个href的GET请求.当然我得到了404错误,因为我把[HTTPDelete]放在我的控制器上.我对Web开发很陌生,所以我确定在javascript或jquery中还有其他方法可以做同样的事情,但我只是在做我现在知道的事情.
我试图通过使用mod_rewrite在php中写一点休息api.
我的问题是:我如何处理HTTP DELETE和PUT?例如,网址为:/ book/1234
其中1234是一本书的唯一ID.我想将这个id(1234)"重定向"到book.php,id为参数.我已经知道如何在php脚本中读取PUT和DELETE变量,但是如何在mod_rewrite中设置这个重写规则?
有任何想法吗?
编辑:GET的重写规则如下所示:
RewriteRule book/([0-9]+) book.php?id=$1 [QSA]
Run Code Online (Sandbox Code Playgroud)
如何为PUT和DELETE执行"参数转发"?据我所知HTTP POST,PUT和DELETE使用HTTP Request Body来传输参数值.所以我想我需要在HTTP请求体中附加参数.但我不知道如何用mod_rewrite做到这一点.
我可以做一些混合DELETE和GET吗?
RewriteCond %{REQUEST_METHOD} =DELETE
RewriteRule book/([0-9]+) book.php?id=$1 [QSA]
Run Code Online (Sandbox Code Playgroud)
然后在book.php中,我会使用$ _GET ['id']来检索book id,即使HTTP HEADER说HTTP METHOD是DELETE.它似乎不起作用......
我正在尝试使用Slim Framework编写的REST API.
Get&Post方法没有任何问题.但是DELETE请求不起作用.我得到" Access-Control-Allow-Methods " 不允许 " 方法删除 "
我已经允许OPTIONS以及标题中的DELETE.见下面的代码.
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Content-Type');
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
$app->options('/(:name+)', function() use($app) {
$response = $app->response();
$app->response()->status(200);
$response->header('Access-Control-Allow-Origin', '*');
$response->header('Access-Control-Allow-Headers', 'Content-Type, X-Requested-With, X-authentication, X-client');
$response->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
});
Run Code Online (Sandbox Code Playgroud)
这个请求失败的原因是什么?
我的Email
Web API 2控制器上有一个操作:
[Authorize]
[RoutePrefix("api/Email")]
public class EmailController : ApiController {
//...
[HttpDelete]
[Route("Remove/{id}")]
private void Remove(int id) {
_repo.Remove(id);
}
}
Run Code Online (Sandbox Code Playgroud)
当我使用DELETE
http://localhost:35191/api/Email/Remove/35571
(或通过任何其他方法)从Fiddler调用该操作时,我得到了一个500
通用的IIS错误页面,它没有提供有关错误的信息.
似乎错误发生在我的操作被调用之前,因为在操作中设置断点会导致断点永远不会被命中.
是否需要某种配置来允许DELETE
IIS(Express)中的方法?
我试过DELETE
在我的web.config中明确允许:
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
Run Code Online (Sandbox Code Playgroud)
但无济于事.
我开始用这种方式:
describe "DELETE /v1/categories/{id}" do
before(:each) do
# Login User/Token
end
it 'deletes a category' do
category = Fabricate(:category)
category2 = Fabricate(:category)
get "/v1/categories"
expect(response.status).to eq 200
expect(JSON.parse(response.body)).to eq([YAML.load(category.to_json),YAML.load(category2.to_json),])
delete "/v1/categories/#{category.id}"
expect(response.status).to eq 200
get "/v1/categories"
expect(JSON.parse(response.body)).to eq([YAML.load(category2.to_json)])
end
end
Run Code Online (Sandbox Code Playgroud)
我不确定是否是测试API请求删除数据的最佳方法.
我想根据简单的条件删除 Elasticsearch 数据库中的一些项目。我尝试通过Postman应用程序来完成。所以我有一个 POST 请求到这个 url localhost:9200/newlocalsearch/_delete_by_query和这个 json 查询:
{
"query": {
"bool": {
"must_not": [
{"exists": {"field": "ico"}}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我向数据库发送请求时,它会返回此错误响应:
{
"took": 51,
"timed_out": false,
"total": 1,
"deleted": 0,
"batches": 1,
"version_conflicts": 1,
"noops": 0,
"retries": {
"bulk": 0,
"search": 0
},
"throttled_millis": 0,
"requests_per_second": -1,
"throttled_until_millis": 0,
"failures": [
{
"index": "newlocalsearch",
"type": "doc",
"id": "0",
"cause": {
"type": "version_conflict_engine_exception",
"reason": "[doc][0]: version conflict, current version [-1] is different than the one …
Run Code Online (Sandbox Code Playgroud) http-delete ×10
ajax ×2
c# ×2
http ×2
rest ×2
spring ×2
actionlink ×1
api ×1
asp.net-mvc ×1
cors ×1
iis-express ×1
java ×1
linkedin ×1
mod-rewrite ×1
php ×1
python ×1
request ×1
rspec ×1
slim ×1
spring-mvc ×1