我有一个基于TypeScript的React应用程序,它托管在我的计算机上。 我使用Spring网关将请求转发到另一个微服务。 GET请求运行正常,但对于POST请求,我得到了以下错误:
Access to XMLHttpRequest at 'http://1.1.1.1:8080/api/support/tickets/create' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
我遇到了这个Spring Cloud Gateway问题:https://github.com/spring-cloud/spring-cloud-gateway/issues/229 React代码:
export async function getTicket(id: string) {
return await axios.get(`${baseUrl}/support/tickets/ticket/${id}`);
}
export async function postTicket(
data: TicketFullDTO
): Promise<AxiosResponse<TicketFullDTO>> {
return await axios.post<TicketFullDTO>(
`${baseUrl}/support/tickets/create`, data);
}
您知道我如何在进行POST
和DELETE
请求之前禁用OPTIONS
请求吗?