开发者

Send XML using urllib

Following this link I tried sending a XML file to my web service using GET:

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()

But it gives me this error:

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)
  F开发者_StackOverflow中文版ile "C:\Python27\lib\httplib.py", line 706, in _set_hostport
    raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
httplib.InvalidURL: nonnumeric port: ''

But if I use POST method described in that link, it works good, my problem is that I need to use GET, so why I am getting thoose errors ?

response = urllib.urlopen(URL, parameter)  // this works


Sending a XML file through a GET request is bare nonsense.

Use POST instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜