我在Post请求体中传递用户名和密码,但它给出的问题是客户端错误:"不接受url: https://apiexample.com/demo "#但是当我使用json文件传递用户名和密码时,它可以工作但我不想传递json文件而是要在请求体
中提供用户名和密码*** Variables ***
${base_Url}= https://apiexample.com
*** Test Cases ***
GenerateToken
${headers}= create dictionary Content-Type=application/json
${body}= create dictionary username=abc@example.in password=abc123
#${body}= get file /Users/Documents/data.json // (but i don't want to use this file method
create session mysession ${base_Url} headers=${headers}
${response}= Post On Session mysession /demo data=${body} headers=${headers}
log to console ${response.status_code}
您需要以JSON格式传递请求正文
*** Settings ***
Library RequestsLibrary
*** Variables ***
&{JSON} username=abc@example.in password=abc123
*** Test Cases ***
Test
create session mysession ${base_Url} headers=${headers}
${response}= Post On Session mysession /demo json=${JSON} headers=${headers}
Log ${response}