Skip to content

Instantly share code, notes, and snippets.

@xgqfrms-GitHub
Last active June 3, 2017 10:54
Show Gist options
  • Save xgqfrms-GitHub/636260e8332f0fe4f530fe040ffd3741 to your computer and use it in GitHub Desktop.
Save xgqfrms-GitHub/636260e8332f0fe4f530fe040ffd3741 to your computer and use it in GitHub Desktop.
HTTP Headers

HTTP Headers

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

demo

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

@xgqfrms-GitHub
Copy link
Author

xgqfrms-GitHub commented Jun 3, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment