我想使用 HttpRequestLibrary 在 Robot Framework 中发出“Content-Type: multipart/form-data”的 POST 请求,但它对我不起作用。
请求的curl是:
curl -X POST "https://xxx-approuter-xxx-xxxxxx" -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "pkcsFile=" -F "crtFile=" -F "privateKey=" -F "jsonBody={'method' = 'BASIC_AUTH', 'username' = 'xxx', 'password' = 'xxxxx'}"
我遇到的问题是我不知道 jsonBody 变量应该在哪里以及如何用 robots scripr 定义。它确实在 Postman 中正常工作,因为在请求的正文中,我可以选择表单数据,然后将键定义为 jsonBody,其值为
{'method' = 'BASIC_AUTH', 'username' = 'xxx', 'password' = 'xxxxx'}
下面是我的机器人脚本的示例:
${headers}= Create Dictionary Content-Type=multipart/form-data Authorization=${token}
${data}= Create Dictionary jsonBody={'method' = 'BASIC_AUTH', 'username' = 'xxx', 'password' = 'xxxxx'}
${resp}= Post Request my_session /authentications data=${data} headers=${headers}
返回错误:
"message": "Required AuthenticationDto parameter jsonBody is not present"
任何人都可以帮助我解决这个问题,或者提供一个如何使用 HttpRequestLibrary 和 Content-Type: multipart/form-data 的正确示例
最佳答案
经过多次尝试,我遇到了这种情况,但也失败了:
Creates an authentication schema
[Arguments] ${providerType} ${providerMode} ${pkcsFile} ${returnStatus}
${headers}= Create Dictionary Content-Type=multipart/form-data Authorization=${jwt_token}
${data}= Create Dictionary method=BASIC_AUTH username=xxx password=xxx
${formData}= Create Dictionary jsonBody=${data}
Log ${formData}
${resp}= Post Request httpbin /configuration/test/test/tests data=${formData} headers=${headers}
Log ${resp}
Should Be Equal As Strings ${resp.status_code} ${returnStatus}
结果是:
"message": "Multipart request resolution failed. Please ensure that each part is properly formatted."
我必须以某种方式提供键值 jsonBody,但我不确定我做得是否正确
关于java - Robotframework.request - 如何发出内容为 “multipart/form-data” 和键值的 POST 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54364813/