我有这样的问题。我是新来的东西。我使用axios HTTP请求npm包编写API调用。但是,当我在控制台上记录响应时,它会像这样显示。
{data: {…}, status: 200, statusText: "OK", headers: {…}, config: {…}, …}
config: {adapter: ƒ, transformRequest: {…}, transformResponse: {…}, timeout: 0, xsrfCookieName: "XSRF-TOKEN", …}
data:
error: {code: 101, type: "missing_access_key", info: "You have not supplied an API Access Key. [Required format: access_key=YOUR_ACCESS_KEY]"}
success: false
__proto__: Object
headers: {content-type: "application/json; Charset=UTF-8"}
request: XMLHttpRequest {onreadystatechange: ƒ, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …}
status: 200
statusText: "OK"
__proto__: Object
它说我没有提供API_key。这就是我编写代码的方式。
const access_key ='my_key'
axios.get(`http://data.fixer.io/api/2013-12-24
? access_key =${access_key} & base = LKR & symbols = ETH`)
.then(res=>{
console.log(res);
})
有人可以帮助我解决此问题吗?谢谢。
答案 0 :(得分:1)
替代
如果您对使用很长的字符串url容易造成错误感到厌倦,则axios
库已经支持替代方法。像这样使用:
const access_key ='my_key'
axios.get('http://data.fixer.io/api/2013-12-24', {
params: {
access_key: access_key,
base: LKR,
symbols: ETH
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})