Python API调用multipart/formd

2024-04-24 06:42:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用Python的--form数据转换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

我所做的:

^{pr2}$

我得到的返回是所有提交样本的默认列表。所以我确信它没有得到所有的头数据。在

我可以用一个传递多个表单数据头的例子。在

谢谢。在


Tags: 数据formtokenapicurlpostexepayload
1条回答
网友
1楼 · 发布于 2024-04-24 06:42:15

使用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

相关问题 更多 >