https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers
https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers
HTTP 消息头允许客户端和服务器通过 request和 response传递附加信息。 一个请求头由不区分大小写的名称后跟一个冒号“:”,然后跟然后值(不带换行符)组成。 该值前面的引导空白会被忽略。
http://www.tutorialspoint.com/http/http_header_fields.htm
https://en.wikipedia.org/wiki/List_of_HTTP_header_fields
fetch('https://newsapi.org/v1/articles?source=the-next-web&sortBy=latest',{
method: 'get',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'X-Api-Key': `0987b00e542141369049e647701b65d9`
}
})
.then(function(response) {
return response.json()
}).then(function(json) {
console.log('parsed json: ', json)
}).catch(function(error) {
console.log('parsing failed: ', error)
});
fetch('https://newsapi.org/v1/articles?source=the-next-web&sortBy=latest&apiKey=0987b00e542141369049e647701b65d9')
.then(function(response) {
return response.json()
}).then(function(json) {
console.log('parsed json: ', json)
}).catch(function(error) {
console.log('parsing failed: ', error)
});
https://gist.github.com/xgqfrms-GitHub/d8afbd6484cf10da3603c6f51d6d4907
CORS
比如,站点 http://domain-a.com 的某 HTML 页面通过
的 src 请求 http://domain-b.com/image.jpg
网络上的许多页面都会加载来自不同域的CSS样式表,图像和脚本等资源。
例如,XMLHttpRequest 和 Fetch 遵循同源策略。
因此,使用 XMLHttpRequest或 Fetch 的Web应用程序只能将HTTP请求发送到其自己的域。为了改进Web应用程序,开发人员要求浏览器厂商允许跨域请求。
https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Access_control_CORS
https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Access_control_CORS#HTTP_请求首部字段
Accept
https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Accept