Python 2.6.4 中的 urllib2:有什么方法可以覆盖 Windows 主机文件?

发布于 2024-08-28 01:45:33 字数 456 浏览 14 评论 0原文

我正在使用 Python 2.6.4 中的 urllib2 模块(在 Windows XP 中运行)来访问 URL。我正在发出一个 post 请求,不涉及 cookie 或 https 或任何太复杂的东西。该域在我的 C:\WINDOWS\system32\drivers\etc\hosts 文件中重定向。但是,我希望 urllib2 的请求转到“真实”域并忽略主机文件中的条目。有什么简单实用的方法可以做到这一点吗?

<罢工> 我希望请求中包含域名,例如:

GET www.example.com/foo.html

而不是

GET 123.45.67.89/foo.html

如果您愿意,请忘记最后一部分。我不需要那么具体地说明标题中的内容。

I am using the urllib2 module in Python 2.6.4, running in Windows XP, to access a URL. I am making a post request, that does not involve cookies or https or anything too complicated. The domain is redirected in my C:\WINDOWS\system32\drivers\etc\hosts file. However, I would like the request from urllib2 to go to the "real" domain and ignore the entry in the hosts file. Is there any easy and practical way to do this?


I would prefer if the request has the domain name in it, for example:

GET www.example.com/foo.html

rather than

GET 123.45.67.89/foo.html

Forget about that last part if you want. I don't need to be that specific about what goes in the header.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄与心 2024-09-04 01:45:33

连接到 IP 地址并手动传递 Host 标头。

Connect to the IP address and pass the Host header manually.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文