Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TooManyRequestsHttpException跨域问题 #20

Open
bilulanlv opened this issue Oct 24, 2024 · 1 comment
Open

TooManyRequestsHttpException跨域问题 #20

bilulanlv opened this issue Oct 24, 2024 · 1 comment

Comments

@bilulanlv
Copy link
Contributor

bilulanlv commented Oct 24, 2024

throw new \Tinywan\ExceptionHandler\Exception\TooManyRequestsHttpException(trans('请求频繁'), ['errorCode' => 4000]);

会报下面的错误,其他请求正常,只有这个TooManyRequestsHttpException会报。
Access to XMLHttpRequest at 'http://192.168.2.66:8789/user' from origin 'http://localhost' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains multiple values '*, http://localhost', but only one is allowed.

我在使用Axios进行跨域请求的时候,无法识别到这个状态,直接返回ERR_NETWORK,在TooManyRequestsHttpException里面设置的请求头似乎影响了这个问题,去掉下面这个 $header请求头就正常了。前提是我有做全局的跨域处理。我不是很懂,你可以确认一下这个情况。

public array $header = [
    'Access-Control-Allow-Origin' => '*',
    'Access-Control-Allow-Credentials' => 'true',
    'Access-Control-Allow-Headers' => '*',
    'Access-Control-Allow-Methods' => 'GET,POST,PUT,DELETE,OPTIONS',
    'X-Rate-Limit-Limit' => 0, //  同一个时间段所允许的请求的最大数目;
    'X-Rate-Limit-Remaining' => 0, // 在当前时间段内剩余的请求的数量;
    'X-Rate-Limit-Reset' => 0 // 为了得到最大请求数所等待的秒数。
];
@Tinywan
Copy link
Owner

Tinywan commented Oct 24, 2024

    'X-Rate-Limit-Limit' => 0, //  同一个时间段所允许的请求的最大数目;
    'X-Rate-Limit-Remaining' => 0, // 在当前时间段内剩余的请求的数量;
    'X-Rate-Limit-Reset' => 0 // 为了得到最大请求数所等待的秒数。

这三个自定义你那边是不是不支持

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants