Python 使用urllib发送XML
接下来,我尝试使用GET将XML文件发送到我的web服务:Python 使用urllib发送XML,python,urllib,Python,Urllib,接下来,我尝试使用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() 但它给了我一个错
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:\eclipse\testing_workspace\http tester\src\Main.py", line 15, in <module>
response = urllib.urlopen(URL + "?%s" % parameter)
File "C:\Python27\lib\urllib.py", line 84, in urlopen
return opener.open(url)
File "C:\Python27\lib\urllib.py", line 205, in open
return getattr(self, name)(url)
File "C:\Python27\lib\urllib.py", line 331, in open_http
h = httplib.HTTP(host)
File "C:\Python27\lib\httplib.py", line 1047, in __init__
self._setup(self._connection_class(host, port, strict))
File "C:\Python27\lib\httplib.py", line 681, in __init__
self._set_hostport(host, port)
File "C:\Python27\lib\httplib.py", line 706, in _set_hostport
raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
httplib.InvalidURL: nonnumeric port: ''
通过GET请求发送XML文件完全是胡说八道
改用POST。您显示的URL不正确;有一个
http://
太多了。
response = urllib.urlopen(URL, parameter) // this works