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格式。
这是你设置的定制请求头,还不是响应头。
2 回答4.9k 阅读✓ 已解决
2 回答1k 阅读✓ 已解决
3 回答1k 阅读✓ 已解决
4 回答822 阅读✓ 已解决
3 回答1.1k 阅读✓ 已解决
1 回答1.6k 阅读✓ 已解决
1 回答1.1k 阅读✓ 已解决
Content-Type 是 Response Header属性,而不是Request Header属性。Request header的属性有User-Agent、Accept、Accept-Language、Cookie以及Connection等等。