【发布时间】:2020-05-22 11:07:48
【问题描述】:
我正在尝试从这个 url (https://documenter.getpostman.com/view/8854915/SzS7R74q?version=latest) 实现一个 api。
API 链接 - https://api.smartable.ai/coronavirus/news/:location
标头 - 订阅密钥:3009d4ccc29e4808af1ccc25c69b4d5d
路径变量 - 位置:美国(示例)
我在 Postman Windows 上测试了这个链接。它返回给我一个 json 响应。但是当我使用相同的标头和路径变量在 react native 上尝试时,它返回了 404 错误。
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Text,
StatusBar,
} from 'react-native';
import axios from 'axios';
export default class NationalNews extends React.Component {
state = {
data: ''
}
componentDidMount() {
axios.get('https://api.smartable.ai/coronavirus/news/:location', {
params: {
"location": "US" //it maybe just IN
},
headers: {
'Subscription-Key': '429058f92b3246ae9b8ad1cd88daee46',
},
method: 'get'
})
.then(function (response) {
// handle success
console.log(response);
})
.catch(function (error) {
// handle error
console.log(error);
})
.then(function () {
// always executed
});
}
render() {
return (
<View>
<Text></Text>
</View>
)
}
}
请帮忙!
【问题讨论】:
标签: javascript node.js reactjs react-native axios