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

cors #65

Closed
userma000913 opened this issue Dec 20, 2022 · 7 comments
Closed

cors #65

userma000913 opened this issue Dec 20, 2022 · 7 comments
Assignees

Comments

@userma000913
Copy link

userma000913 commented Dec 20, 2022

Is your feature request related to a problem? Please describe.

A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like

A clear and concise description of what you want to happen.

Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.

Additional context

Add any other context or screenshots about the feature request here.

POST http://localhost:5173/api/route_name 500 (Internal Server Error)
前后端联调时,一直报500,应该就是后端的跨域配置有问题, 前端配置了 myAxios.defaults.withCredentials = true;
后端使用cors无效
h.Use(cors.New(cors.Config{
AllowAllOrigins: true,
AllowCredentials: true,
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"},
AllowHeaders: []string{"Origin", "Content-Length", "Content-Type"},
}))

换成gin框架就可以,是我配置的有问题嘛

@BaiZe1998
Copy link
Contributor

Is your feature request related to a problem? Please describe.

A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like

A clear and concise description of what you want to happen.

Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.

Additional context

Add any other context or screenshots about the feature request here.

POST http://localhost:5173/api/route_name 500 (Internal Server Error) 前后端联调时,一直报500,应该就是后端的跨域配置有问题, 前端配置了 myAxios.defaults.withCredentials = true; 后端使用cors无效 h.Use(cors.New(cors.Config{ AllowAllOrigins: true, AllowCredentials: true, AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"}, AllowHeaders: []string{"Origin", "Content-Length", "Content-Type"}, }))

换成gin框架就可以,是我配置的有问题嘛

Can you show the error message from the hertz server?

@userma000913
Copy link
Author

hertz没报错。。。

@BaiZe1998
Copy link
Contributor

hertz没报错。。。

Maybe you can show the debug information of the browser in developer mode.
And I would like to know the content of the request (HTTP Header & Body) initiated by your client, does it contain the Origin header field?

@userma000913
Copy link
Author

hertz没报错。。。

Maybe you can show the debug information of the browser in developer mode. And I would like to know the content of the request (HTTP Header & Body) initiated by your client, does it contain the Origin header field?

image

@BaiZe1998
Copy link
Contributor

BaiZe1998 commented Dec 20, 2022

hertz没报错。。。

Maybe you can show the debug information of the browser in developer mode. And I would like to know the content of the request (HTTP Header & Body) initiated by your client, does it contain the Origin header field?

image

Is this the preflight request with the corresponding response, and can you show the 500 error message you mentioned?
By the way, i found some fields missing in the response header.

@userma000913
Copy link
Author

hertz没报错。。。

Maybe you can show the debug information of the browser in developer mode. And I would like to know the content of the request (HTTP Header & Body) initiated by your client, does it contain the Origin header field?

image

Is this the preflight request with the corresponding response, and can you show the 500 error message you mentioned? By the way, i found some fields missing in the response header.

image

我好像找到问题所在了

@BaiZe1998
Copy link
Contributor

myAxios.defaults.withCredentials = true;

This doesn't seem to be a server-side issue, is it related to the myAxios.defaults.withCredentials = true you mentioned? If you find an idea to solve the problem, please share it.

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

No branches or pull requests

3 participants