Java RobotFramework体上带有属性的Post请求
您好,我正在尝试使用主体测试api:Java RobotFramework体上带有属性的Post请求,java,post,robotframework,broadleaf-commerce,document-body,Java,Post,Robotframework,Broadleaf Commerce,Document Body,您好,我正在尝试使用主体测试api: { "customerAttributes": [ { "customerId": 0, "id": 0, "name": "string", "value": "string" } ], "emailAddress": &q
{
"customerAttributes": [
{
"customerId": 0,
"id": 0,
"name": "string",
"value": "string"
}
],
"emailAddress": "string",
"firstName": "string",
"id": 0,
"lastName": "string",
"registered": true
}
因为它有不止一个物体,我不知道如何使它工作。这就是我现在所拥有的:
*** Settings ***
Library RequestsLibrary
*** Variables ***
${Base_URL}= http://localhost:8082 /api/v1
*** Test Cases ***
TC_004_POST_Customer
Create session customer ${Base_URL}
${body}= create dictionary customerId=100 id=100 name=test value=0 emailAdress=blabla@gmailcom firstName=algo id=101 lastName=testt registered=true
${header}= create dictionary Content-Type=application/json
${response}= Post On Session customer /customer data=${body} headers=${header}
log to console ${response.status_code}
log to console ${response.content}
有人能帮我一下吗?谢谢 您应该能够执行以下操作:
${inner}= Create Dictionary customerId=100 id=100 name=test value=0
${array}= Create List ${inner}
${body}= Create Dictionary customerAttributes=${array} emailAdress=blabla@gmailcom firstName=algo id=101 lastName=testt registered=True
您应该能够执行以下操作:
${inner}= Create Dictionary customerId=100 id=100 name=test value=0
${array}= Create List ${inner}
${body}= Create Dictionary customerAttributes=${array} emailAdress=blabla@gmailcom firstName=algo id=101 lastName=testt registered=True
您必须在
POST-on-Session
关键字中使用json
参数,如下所示:
TC_004_POST_Customer
Create session customer ${Base_URL}
${body}= create dictionary customerId=100 id=100 name=test value=0 emailAdress=blabla@gmailcom firstName=algo id=101 lastName=testt registered=true
${header}= create dictionary Content-Type=application/json
${response}= Post On Session customer /customer json=${body} headers=${header}
log to console ${response.status_code}
log to console ${response.content}
这是文档您必须在
POST on Session
关键字中使用json
参数,如下所示:
TC_004_POST_Customer
Create session customer ${Base_URL}
${body}= create dictionary customerId=100 id=100 name=test value=0 emailAdress=blabla@gmailcom firstName=algo id=101 lastName=testt registered=true
${header}= create dictionary Content-Type=application/json
${response}= Post On Session customer /customer json=${body} headers=${header}
log to console ${response.status_code}
log to console ${response.content}
这是文档Dint work:(我应该在响应中更改其他内容吗?如果您看到json响应,还应该在标题中添加Accept=application/json。我不知道这是否只是您在此处发送代码的方式,但您的意图不正确,而且基本url中有一个空格。Dint work:(我应该在响应中更改其他内容吗?如果您看到json响应,还应该在您的标题中添加Accept=application/json。我不知道这是否只是您在此处发送代码的方式,但您的意图不正确,而且在Base_url中有一个空格。太棒了!谢谢,现在它确实起作用了:D只需要像您所说的那样将数据更改为json。谢谢mazing!谢谢,现在它成功了:D只需像您所说的那样将数据更改为json。谢谢