【发布时间】:2019-04-27 00:37:58
【问题描述】:
我想使用 RequestsLibrary 在 Robot Framework 中使用“Content-Type: multipart/form-data”发出 POST 请求,但似乎没有任何效果。 发出此请求的关键字如下所示:
*** Variables ***
&{API_CREDS} username=myusername password=mypwd
*** Keywords ***
Get token
# Assumes that session has been created
[Arguments] ${Session_id}
&{headers}= create dictionary Content-Type=multipart/form-data
${response}= Post Request ${Session_id} ${AUTH_TOKEN_URL_PATH} data=${API_CREDS} headers=${headers}
should be equal as integers ${response.status_code} 200
[Return] ${response.json()['token']}
但实际发送的 POST 请求不包含“Content-Type”标头,正文只是一个原始的data={'username' = 'myusername', ' password' = 'mypwd'}
我已经尝试了很多我发现的东西,但没有任何效果。 Robot Framework 的RequestsLibrary 是否真的支持发送带有“Content-Type: multipart/form-data”的 POST 请求?如果是,这是怎么做的?
PS:我在Windows 10 和Python 3.7.1 上使用Robot Framework。
POST 请求实际上是发送的,但它不包含 Content-Type 标头,也不包含 form-data 有效负载,如上所述。
【问题讨论】:
标签: python python-requests robotframework