您将必须设置一个自定义标头
host,其值为
example.com,例如:
requests.get('http://127.0.0.1/foo.php', headers={'host': 'example.com'})应该可以。如果要验证,请键入以下命令(需要netcat):
nc -l -p 80然后运行上面的命令。它将在netcat窗口中产生输出:
GET /foo.php HTTP/1.1Host: example.comConnection: keep-aliveAccept-Encoding: gzip, deflateAccept: */*User-Agent: python-requests/2.6.2 CPython/3.4.3 Windows/8



