我正在尝试使用Python的--form data来转换curl调用
curl -H "X-API-TOKEN:xxxxxxxxxxxxxxxxxxxxxxxxxx" -X POST \
--form upload=@2015-07-02-Fiesta-EK-malware-payload.exe \
--form "owner=userName" https://192.168.1.198/rapi/samples/basic我尝试过的:
url = 'https://%s/rapi/samples/basic' % hostname
q = Request(url)
q.add_header('X-API-TOKEN', 'xxxxxxxxxxxxxxxxxxxxxxxxxx')
q.add_header('Content-Type', 'multipart/form-data; upload=@%s' % fileName)
q.add_header('Content-Type', 'multipart/form-data; owner=userName')
a = urlopen(q).read()我得到的返回值是所有已提交样本的默认列表。所以我确信它不会得到所有的头数据。
我可以使用一个传递多个表单数据头的示例。
谢谢。
发布于 2016-01-20 01:17:35
使用unirest的示例调用
import unirest
# consume async post request
def consumePOSTRequestSync():
params = {'test1':'param1','test2':'param2'}
# we need to pass a dummy variable which is open method
# actually unirest does not provide variable to shift between
# application-x-www-form-urlencoded and
# multipart/form-data
params['dummy'] = open('dummy.txt', 'r')
url = 'http://httpbin.org/post'
headers = {"Accept": "application/json"}
# call get service with headers and params
response = unirest.post(url, headers = headers,params = params)
print "code:"+ str(response.code)
print "******************"
print "headers:"+ str(response.headers)
print "******************"
print "body:"+ str(response.body)
print "******************"
print "raw_body:"+ str(response.raw_body)
# post sync request multipart/form-data
consumePOSTRequestSync()您可以查看此博客以获取更多详细信息http://stackandqueue.com/?p=57
https://stackoverflow.com/questions/32792646
复制相似问题