在此链接之后,我尝试使用GET将XML文件发送到我的web服务:
import urllib
from createfile import XML
URL = "http://http://localhost:8080/mywebservice
parameter = urllib.urlencode({'XML': XML})
response = urllib.urlopen(URL + "?%s" % parameter)
print response.read()
但是它给了我这个错误:
Traceback (most recent call last):
File "C:eclipsetesting_workspacehttp testersrcMain.py", line 15, in <module>
response = urllib.urlopen(URL + "?%s" % parameter)
File "C:Python27liburllib.py", line 84, in urlopen
return opener.open(url)
File "C:Python27liburllib.py", line 205, in open
return getattr(self, name)(url)
File "C:Python27liburllib.py", line 331, in open_http
h = httplib.HTTP(host)
File "C:Python27libhttplib.py", line 1047, in __init__
self._setup(self._connection_class(host, port, strict))
File "C:Python27libhttplib.py", line 681, in __init__
self._set_hostport(host, port)
File "C:Python27libhttplib.py", line 706, in _set_hostport
raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
httplib.InvalidURL: nonnumeric port: ''
但是如果我使用该链接中描述的POST方法,它工作得很好,我的问题是我需要使用GET,那么为什么我得到这些错误?
response = urllib.urlopen(URL, parameter) // this works
通过GET请求发送XML文件是完全没有意义的。
用POST代替