简体   繁体   English

从反应 POST 请求收到的打开 URL

[英]Opening URL received from react POST request

I have successfully conducted an API call and I can see the correct response in my console.我已经成功进行了 API 调用,并且可以在控制台中看到正确的响应。 Is it possible to redirect my react app from the local hose to the url received (in this case the one called Gatewayurl under data)?是否可以将我的反应应用程序从本地软管重定向到收到的 url (在这种情况下,数据下称为 Gatewayurl)? Any help is appreciated任何帮助表示赞赏

{data: {…}, status: 202, statusText: "", headers: {…}, config: {…}, …}
config: {url: "yahoo.com", method: "post", data: "{"referenceNumber":"string"}", headers: {…}, transformRequest: Array(1), …}
data:
GatewayUrl: "google.com"   //THIS IS THE URL I WANT TO REDIRECT TO
referenceNumber: "C1234"
__proto__: Object
headers: {content-type: "application/json;charset=UTF-8"}
request: XMLHttpRequest {readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, onreadystatechange: ƒ, …}
status: 202
statusText: ""
__proto__: Object

This is my code:这是我的代码:

axios.post('https::/yahoo.come/send', data, config)
        .then((data)=>{
            console.log(data);  
        })
        .catch((err) => {
            console.log(err);
        })

Use window.location.href使用window.location.href

...
.then((data)=>{
     console.log(data);  
     window.location.href = 'http://google.com'
})
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM