我已经使用过Web API,并且遇到了很多问题,例如发布多个参数.我升级到WebApi2以使用路由属性,现在遇到如下问题:
"message":"The requested resource does not support http method 'DELETE'."
我花了一整天时间搜索Stack Overflow和Web来解决问题:
webdavhttp protocol允许所有get,put,post,delete[HTTPDelete]属性name="ExtensionlessUrlHandler-Integrated-4.0" path="*."
verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS"
type="System.Web.Handlers.TransferRequestHandler"
preCondition="integratedMode,runtimeVersionv4.0"有人可以指导我吗?
Vin*_*oth 21
我有同样的问题.将以下代码添加到web.config应该可以解决以下问题system.webserver:
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule"/>
Run Code Online (Sandbox Code Playgroud)
小智 10
我有同样的问题,因为我的控制器是这样的:
[HttpDelete]
public HttpResponseMessage Delete(string Id)
{
....
}
Run Code Online (Sandbox Code Playgroud)
在客户端我使用发送ID作为请求正文:
var url = '/api/upload';
var data = JSON.stringify({ 'Id': id }); // <-- In the body
$.ajax({
url: url,
type: 'DELETE',
data: data, // <-- in the body
contentType: 'application/json'
})
Run Code Online (Sandbox Code Playgroud)
当我更改客户端以将其用作URL参数时,它工作:
var url = '/api/upload/' + id; // <- In the URL
$.ajax({
url: url,
type: 'DELETE',
contentType: 'application/json'
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17923 次 |
| 最近记录: |