CORS:即使服务器响应中包含适当的Access-Control-Allow-Header,自定义标头也无法通过预检

时间:2018-08-08 20:29:10

标签: cors

在阅读了所有先前的问题/答案以及指向CORS的链接(谢谢!)之后,我确实设法正确设置了服务器并发送了通过预检的POST请求。但是,我的下一个POST请求需要一个自定义标头(特别是oauth-token)。目前,我无法通过POST请求中包含的自定义标头进行预检。

服务器当前设置为:

    Header set Access-Control-Allow-Origin "*"
    Header set Access-Control-Allow-Methods "POST, GET"
    Header set Access-Control-Allow-Headers "oauth-token"

以下是我当前正在发送/接收的请求和响应。如果我发送的请求没有任何标题,预检将通过。我希望有人能看到我想念的东西。

请求:

OPTIONS /sugar/rest/v11/globalsearch HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Access-Control-Request-Method: POST
Origin: http://localhost:4200
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36
Access-Control-Request-Headers: oauth-token
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9

响应:

HTTP/1.1 404 Not Found
Date: Wed, 08 Aug 2018 19:18:32 GMT
Server: Apache/2.4.18 (Ubuntu)
Cache-Control: no-store
Content-Length: 78
Status: 404 Not Found
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST, GET
Access-Control-Allow-Headers: oauth-token
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: application/json

其他信息:我从与对同一服务器的不同POST请求相关联的OPTIONS请求中收到200 OK。

对POST请求的前响应,不包括标题:

HTTP/1.1 200 OK
Date: Wed, 08 Aug 2018 19:18:30 GMT
Server: Apache/2.4.18 (Ubuntu)
Set-Cookie: PHPSESSID=a09u0sp3ldf1qku4ip4p107hq4; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Set-Cookie: download_token_base=0427fc00-912a-4bf7-b1d1-2edd99faaff0; 
expires=Wed, 22-Aug-2018 19:18:31 GMT; Max-Age=1209599; path=/; HttpOnly
Vary: Accept-Encoding
Content-Encoding: gzip
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST, GET
Access-Control-Allow-Headers: oauth-token
Content-Length: 189
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/json

0 个答案:

没有答案