reactjs - 为什么 post man 中的 api 请求和 react native 中的 api fetch 请求有不同的响应
问题描述
fetch(`${valid_url}`, {
method:"GET",
headers:{
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/51.0.2704.47 Safari/537.36"
}
}).then((response) => response.text())
.then((result) => {
console.log(result)
...
解决方案
添加有效标题
fetch("Add URL Here", {
method: "GET",
headers: {
// Add valid header here
Accept: "application/json",
"Content-Type": "application/json",
},
})
.then((response) => response.json())
.then((responseJson) => {
API Responce here
console.log(responseJson);
// setState(responseJson.VAlue);
})//
.catch((error) => {
alert(error);
});
推荐阅读
- vue.js - 如果单击另一个手风琴项,Vue.js Accordion 不应关闭
- android - Flutter 小部件功能
- angular - NGXS store 中的数据是如何存储的?ngxs store 的内存限制是多少?ngxs 在浏览器中存储内存在哪里?
- javascript - 通过浏览器的后退按钮取消异步数据 api 调用时,有什么方法可以返回到同一页面
- python - 限制形成相关模型中选择的外键
- laravel - Laravel 验证如果两个字段都为空则错误。但如果一个为空,则需要另一个
- python - 如何像普通的python文件一样运行gimp?
- c# - 在 ASP.NET MVC 中通过 JQuery AJAX 上传文件
- node.js - csv-parser 无法读取或打开此类 .csv 文件
- angular - 如何在我的角度应用程序中更改动画进度条的颜色