python
import requests url = 'http://www.baidu.com' headers = {'Content-Type': 'application/json'} r = requests.get(url, headers=headers) print r.headers['Content-Type']
输出的内容为text/html; charset=utf-8
而不是我设置的application/json
何解?
BTW python2.7.9
python
import requests url = 'http://www.baidu.com' headers = {'Content-Type': 'application/json'} r = requests.get(url, headers=headers) print r.headers['Content-Type']
输出的内容为text/html; charset=utf-8
而不是我设置的application/json
何解?
BTW python2.7.9
因为这个 www.baidu.com 返回的内容就是 text/html; charset=utf-8;
设置的headers = {'Content-Type': 'application/json'}是表示你传入的数据是json格式。
这是你设置的定制请求头,还不是响应头。
4 回答4.4k 阅读✓ 已解决
4 回答3.8k 阅读✓ 已解决
1 回答3k 阅读✓ 已解决
3 回答2.1k 阅读✓ 已解决
1 回答4.5k 阅读✓ 已解决
1 回答3.8k 阅读✓ 已解决
1 回答2.8k 阅读✓ 已解决
Content-Type 是 Response Header属性,而不是Request Header属性。Request header的属性有User-Agent、Accept、Accept-Language、Cookie以及Connection等等。