【问题标题】:CORS Error on POST with no contentPOST 上的 CORS 错误,没有内容
【发布时间】:2018-07-26 07:33:15
【问题描述】:

我有一个控制器样式的 REST Web 服务端点,如果我发布非空内容,它将在浏览器中工作,但是当内容为空时,浏览器返回:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 403. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

这是一个内容有效的请求:

POST /my/controller/resource HTTP/1.1
Host: localhost:8083
Connection: keep-alive
Content-Length: 1
accept: application/json
Origin: null
Authorization: Bearer JWT
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
Content-Type: application/json
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9

HTTP/1.1 204 No Content
Server: Apache-Coyote/1.1
Access-Control-Allow-Origin: null
Access-Control-Allow-Credentials: true
Content-Language: en-US
Date: Thu, 15 Feb 2018 13:44:53 GMT

这是一个没有内容的请求,不起作用

POST /my/controller/resource HTTP/1.1
Host: localhost:8083
Connection: keep-alive
Content-Length: 0
accept: application/json
Origin: null
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
Authorization: Bearer JWT
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9

HTTP/1.1 403 Forbidden
Server: Apache-Coyote/1.1
Content-Type: text/plain
Content-Length: 0
Date: Thu, 15 Feb 2018 13:42:16 GMT

谁能解释为什么没有内容的请求不起作用 - 以及我可以做些什么来纠正这个问题?

【问题讨论】:

    标签: rest post cors


    【解决方案1】:

    这似乎不是 CORS 错误 - 服务器设置为不允许零内容长度的 POST 请求。这就是抛出 403 错误响应的原因。

    【讨论】:

      猜你喜欢
      • 2022-01-06
      • 2020-10-04
      • 2023-03-03
      • 2015-05-01
      • 2021-12-13
      • 2019-11-05
      • 1970-01-01
      • 2017-08-15
      • 2021-01-13
      相关资源
      最近更新 更多