【发布时间】:2018-04-17 00:17:12
【问题描述】:
我正在尝试编写一个提交表单,将 JSON 对象发送到另一台服务器上的应用程序,但我在控制台中不断收到 405 Method Not Allowed 错误。
应用程序设置为接受POST,这就是我要发送的内容,所以我迷失了错误所在。控制台中也有警告Loading failed for the <script> with source "Request URL"
这是应用程序读取 JSON 的方式或发送 JSON 的格式有问题吗?
来自应用服务器
Failed to execute: javax.ws.rs.NotSupportedException: RESTEASY003065: Cannot consume content type
代码
json = JSON.parse(string);
$.ajax({
type: 'POST',
dataType: "jsonp",
contentType: "application/json",
url: "http://test:8080/request/committee",
data: json,
cache: false,
success: function (response) {
$("#successModal").modal('show');
},
failure: function (response) {
$("#failureModal").modal('show');
},
error: function (response) {
$("#failureModal").modal('show');
}
});
e.preventDefault();//prevents the form from being submitted by default
请求标头
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.5
Connection: keep-alive
Host: test:8080
Referer: http://www.form.com/servlet/rsvp.jsp?location=110%20Road%20Bolton%20Landing,%20NY&purpose=%20TPAS%20Teleconference%20(RSVP%20here%20to%20attend%20in-person)&visitDate=2018-03-15&visitStartTime=6:00%20AM&visitEndDate=7:00%20AM&committee=all
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0
响应标头
HTTP/1.1 405 Method Not Allowed
Allow: POST, OPTIONS
Connection: keep-alive
Content-Length: 0
Date: Mon, 16 Apr 2018 15:38:24 GMT
编辑:更正contentType。出现同样的错误
【问题讨论】:
-
type: 'POST',->method: 'POST' -
试试
contentType: "application/json"。只使用 JSONP 作为返回类型,不用于发送。 -
你为什么使用jsonp?您是否在使用常规 json 进行跨站点请求时遇到问题?
-
@Keith,很好。
-
您不能在 JSONP 中使用 POST 请求。
标签: javascript jquery json ajax