本文介绍了Python相当于Curl HTTP post的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用curl从命令行使用以下方式发布到Hudson服务器:
I am posting to Hudson server using curl from the command line using the following--
curl -X POST -d '<run><log encoding="hexBinary">4142430A</log><result>0</result><duration>2000</duration></run>' \
http://user:pass@myhost/hudson/job/_jobName_/postBuildResult
hudson documentation..can我可以模仿同样的事情使用python..i不想使用pyCurl或发送这行通过os.system()..是有ny出口使用原始的python ??
as shown in the hudson documentation..can I emulate the same thing using python..i don't want to use pyCurl or send this line through os.system()..is there ny way out using raw python??
推荐答案
import urllib2
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
result = response.read()
您可以使用urllib对dict进行编码,如下所示:
You can encode a dict using urllib like this:
import urllib
values = { 'foo': 'bar' }
data = urllib.urlencode(values)
这篇关于Python相当于Curl HTTP post的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!