为什么我的程序可以连接到不存在的网站? [英] How come my program can connect to a nonexistent website?

查看:173
本文介绍了为什么我的程序可以连接到不存在的网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是python和网络编程的新手,我遇到了一个简单程序的问题。我基本上打开一个不存在的网站的连接,不知何故似乎连接成功。此外,我得到一个200返回代码,这意味着http服务器已响应它存在并且连接正常。这是我的代码的相关部分:

I am new to python and network programming and I am having trouble with a simple program. I am basically opening a connection to a nonexistent website and somehow it seems that the connection succeeds. Moreover, I get a 200 return code which means the http server has responded that it exists and the connection is OK. Here's the relevant part of my code:

import httplib

conn = httplib.HTTPConnection("Nonexistentsite.com", 80)
conn.request("GET","/")
r  = conn.getresponse()
print r.status, r.reason
conn.close()

当我尝试 google.com 或任何其他现有网站,而不是 nonexistentsite.com ,我得到301或302 - 永久移动

And when I try google.com or any other existing website instead of nonexistentsite.com, I get 301 or 302 - Moved permanently.

请你澄清为什么会发生这种情况,拜托?如果重要的话,我正在使用visualStudio2010(IronPython)。

Could you kindly clarify why this is happening, please? I am using visualStudio2010(IronPython) if that matters.

推荐答案

您可能正在使用伪造DNS结果的ISP以便提供你是一个垃圾邮件页面有用的搜索页面,而不是非限制名称的错误。

You might be using an ISP that fakes DNS results in order to give you a spam page helpful search page instead of an error for nonexistant names.

ping是什么?Nonexistentsite.com 会在您测试Python代码的机器上产生吗?

What does a ping Nonexistentsite.com result in on the machine where you tested your Python code?

这篇关于为什么我的程序可以连接到不存在的网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆