Pyton在请求Http时,先要建立连接,而建立连接的地址必须是机器的IP:PORT或域名(域名解析也必须指到IP:PORT)。这与其他语言编程不同,如Java。
如果是到容器应用级别,比如你Tomcat下跑某个app应用,如果你到xx.xx.xx.xx/app则不行,必须是xx.xx.xx.xx
所以你在编程时,如果别人传你地址,戴取ip:PORT(或域名)时要split("/")[0],千万要注意。原则就是只取IP:PORT,记住。
如下处理
def postMainHost(fileUrl, fileUUID):
"""
访问主机,下载文件内容
:param fileUrl::主机域名orIP
:param fileUUID: 下载文件的唯一标识
:return:
"""
print "postMainHost"
requrl = "http://{fileUrl}/commCallback/getFileContent".format(fileUrl=fileUrl)
conn = httplib.HTTPConnection(fileUrl.split("/")[0])
headers = {'content-type': 'application/json'}
print requrl
conn.request(method="POST", url=requrl, body=fileUUID, headers=headers)
response = conn.getresponse()
res = response.read()
return res