问题描述
我正在开发一个React应用程序,由于机密性,该应用程序需要在主体内发送对象参数.因此,我正在像这样从React App客户端向后端服务器发出POST请求
I am working on a react application, where there is a need to send the object parameters inside a body because of confidentiality. So I am making a POST request from the react app client-side to the backend server like this
axios
.post('htps://java.backend.xyz/path1', {
data: password,
})
.catch(function (error) {
handle(error);
});
发出此POST请求后,将出现一个带有"method = OPTIONS"的预检请求.和"URL ='htps://java.backend.xyz/path1'" ... java-backend-server以status_code = 200进行响应.
After making this POST request there is a preflight request with "method = OPTIONS" and "URL= 'htps://java.backend.xyz/path1'"...to which java-backend-server responds with status_code=200.
上述预检请求之后,java-backend-server处理POST请求,而不是发送Java后端服务器以GET请求(即重定向)进行响应,例如:
After the above preflight request, java-backend-server addresses the POST request and instead of sending a response the java-backend-server respond with a GET request (i.e redirect) as for example:
https://express-app.xyz/path2?query_para1=abc&query_param2=123, requestMethod=GET
响应上述GET请求,快速应用将以status_code = 200进行响应
And in response to the above GET request, the express app responds with status_code=200
但是在此GET请求之后,立即有一个预检请求,其请求方法为Method = OPTIONS,并且具有与上述网址相同的网址,即
But immediately after this GET request, there is a preflight request with request Method=OPTIONS and having the same URL as above i.e
https://express-app.xyz/path2?query_para1=abc&query_param2=123, requestMethod=OPTIONS
,对于上述OPTIONS请求,快递服务器以status_code = 204进行响应,这意味着客户端不需要从当前页面导航离开……这是在禁止我的应用进行最终重定向,即在后端服务器以GET请求进行响应,即使搜索引擎未更新重定向网址,我的React应用也无法进行重定向
and for this above OPTIONS request express server responds with a status_code=204 which means that the client doesn't need to navigate away from its current page...this is something prohibiting my app to make a final redirect i.e after the backend server responds with a GET request, my react app is not able to make a redirect even search engine does not update the redirect URL which is
https://express-app.xyz/path2?query_para1=abc&query_param2=123
那么,这有可能吗?我假设GET请求之后的预检请求禁止客户端进行最终重定向.有人可以在这种情况下为我提供帮助
So, here Is this even possible? I am assuming that the preflight request after the GET request prohibits the client side to be able to make a final redirect. Can someone please help me with this scenario
推荐答案
我不确定我是否正确理解了您的问题,但是您可以做的是发送回复,该回复将指示客户端重定向到特定位置.这可以通过发送带有状态码302和标头中的位置(location:redirect_url)的响应来实现
I am not sure if I understand your problem correctly but what you can do is send a post response which will which will indicate client to redirect to specific location.This can be achieved by sending response with status code 302 and location in header (location:redirect_url)
有关更多信息:- https://en.m.wikipedia.org/wiki/HTTP_302
这篇关于POST请求可以重定向为另一个GET请求吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!