Python 2.7 从cUrl到python2.7
我需要将以下cUrl命令转换为Python 2.7:Python 2.7 从cUrl到python2.7,python-2.7,curl,Python 2.7,Curl,我需要将以下cUrl命令转换为Python 2.7: curl -X POST --data-binary @myfile http://127.0.0.1/process/my/data 我在谷歌上搜索了这个,但我只找到了发布字段或文件的示例,而没有将文件内容发送到请求的正文中。对于那些感兴趣的人,以下是答案: # -*- coding: utf-8 -*- import httplib2 h = httplib2.Http(".cache") resp, content = h.requ
curl -X POST --data-binary @myfile http://127.0.0.1/process/my/data
我在谷歌上搜索了这个,但我只找到了发布字段或文件的示例,而没有将文件内容发送到请求的
正文中。对于那些感兴趣的人,以下是答案:
# -*- coding: utf-8 -*-
import httplib2
h = httplib2.Http(".cache")
resp, content = h.request("http://127.0.0.1/requests",
"POST", body="Here is the content of the file you want to post",
headers={'Content-type': 'application/json'}
)
print resp
为什么是-1?,你能解释一下吗?。