Laravel Cors问题,对外部资源的400错误请求

时间:2019-02-05 10:13:37

标签: php laravel .htaccess header cors

我正在尝试在laravel项目中加载外部资源,但是却收到400 Bad Request响应。

如果我加载google chrome并禁用网络安全,则资源加载正常。我以前看过一些文章,说启用cors应该可以解决问题,但对我来说还没有解决。我已经通过httpstatus.io运行了域,并显示了以下标头

Date

Tue, 05 Feb 2019 09:38:23 GMT

Server

Apache

X-Powered-By

PHP/7.2.14

Access-Control-Allow-Origin

*

Cache-Control

no-cache, private

Referrer-Policy

strict-origin

Connection

close

Transfer-Encoding

chunked

Content-Type

text/html; charset=UTF-8

Set-Cookie

XSRF-TOKEN=eyJpdiI6Im9oampzZmlOR3VJRlVzUWtKZG1wOHc9PSIsInZhbHVlIjoiUFRyR3I1NitPdzd3Z0tVZ05OOE1oNGxSa3pGbGsxNHVcL1NvK2lMYXNhVVZSYllEQW1IWGUwd0dyNnRKa3VcLzVMYTN0bm82cTVHMjlmbThQTXMyc05rQT09IiwibWFjIjoiOTk5ZWM2ZThmZjkzNGE5NWM1NjIxMjE5NjQ3YjU5MzRkZGM2ZTg4ODljMWY0NjZjZjZkZDU4MTQwNmY5ZjEzMiJ9; expires=Tue, 05-Feb-2019 11:38:23 GMT; Max-Age=7200; path=/

Set-Cookie

sportswise_session=eyJpdiI6IkU4VVk4cmpvTXh0T1JESWVTQzRRMkE9PSIsInZhbHVlIjoiVE91VEZPUG90aFlwWXZ1RXRvdzlFcEs3WU5Scm5jaXVjaW5LeXF6c1J4NXJVWHdSK3ZDYXAyRjFxWE1cL0JNK3RzMXRaekI3Y1dPRzFYc1BJYmlJNlwvUT09IiwibWFjIjoiZjQ2YmNkYzU2YzRkMzU0YTc5ZmViNjgxYWMyYTRkMGExNGYwNzY5ZjFjODk2YjA4MjFmN2EyMGY2N2RiYjU3YiJ9; expires=Tue, 05-Feb-2019 11:38:23 GMT; Max-Age=7200; path=/;

httponly

,其中包括allow *标头。我从请求中获得的网络响应是

常规

Request URL: [my external request url]

Request Method: OPTIONS 

Status Code: 400 Bad Request 

Remote Address: [my remote address]

Referrer Policy: strict-origin

响应标题

Access-Control-Allow-Credentials: true

Access-Control-Allow-Origin: [my domain] 

Cache-Control: no-cache

Connection: keep-alive 

Content-Length: 88763

Content-Type: text/html

请求标头

Provisional headers are shown 

Access-Control-Request-Headers: x-xsrf-token 

Access-Control-Request-Method: GET 

Origin: [my domain]

Referer: [my domain] 

User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36

是否缺少任何请求?我在应用程序上添加了CORs中间件,并尝试在访问中添加标头,但似乎没有什么可以改变不良响应

0 个答案:

没有答案