[英]From cURL to JavaScript fetch()
I have a cURL example of an request to a rest API, but I can't seem to replicate it correctly in JavaScript with fetch. I have a cURL example of an request to a rest API, but I can't seem to replicate it correctly in JavaScript with fetch. Would any of you please help me out?
你们中的任何人都可以帮帮我吗? here is the cURL example:
这是 cURL 示例:
curl https://api.sparebank1.no/open/personal/banking/accounts/all --header "Authorization:Bearer 9VKwFeoS8QfeQEeFxD5MiOf6YlFQR0nOpLF1ZUrHRrWqp3rY7G13hy"
Thx谢谢
Here it is:这里是:
fetch('https://api.sparebank1.no/open/personal/banking/accounts/all', {
headers: {
Authorization: 'Bearer 9VKwFeoS8QfeQEeFxD5MiOf6YlFQR0nOpLF1ZUrHRrWqp3rY7G13hy'
}
});
The fetch function takes a first parameter, the URL.提取 function 采用第一个参数 URL。 The second parameter is an object containing keys that describe your request, such as
method
or headers
.第二个参数是 object 包含描述您的请求的键,例如
method
或headers
。
In our case, it's specifying a headers object.在我们的例子中,它指定了一个头文件 object。 This contains key-value pairs of named headers and their corresponding values.
这包含命名标头的键值对及其对应的值。
I recommend viewing MDN (if you haven't), it's a useful resource.我推荐查看MDN (如果你还没有),这是一个有用的资源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.