简体   繁体   English

Rest 保证 400 错误请求

[英]Rest Assured 400 Bad Request

I writing an automation code in rest assured but it return 400 Bad Request and I don't know how to debug it.我在 rest 中编写了一个自动化代码,但它返回 400 Bad Request,我不知道如何调试它。 Hope someone can help.希望有人可以提供帮助。

In postman, i must specify the username and password using raw approach.在 postman 中,我必须使用原始方法指定用户名和密码。 It will fail on form-data.它将在表单数据上失败。 How to specify raw data in rest-assured?如何在放心中指定原始数据?

Curl: Curl:

curl --location --request POST 'http://127.0.0.1:8010/api/v1/account/webapi/account/users/secure/webEncryptLogin?checkHash=false%0A' \
--header 'device_token: wap' \
--header 'Content-Type: application/json' \
--data-raw '{
  "username": "peter1",
  "password": "SomeSecretPassword"
}'

Rest Assured Java Code: Rest 保证 Java 代码:

given().
                    contentType("application/json").
                    queryParam("checkHash", "false").
                    header("device_token", "wap").
                    params("username", "peter1", "password","SomeSecretPassword").
            when().
                    post("http://127.0.0.1:8010/api/v1/account/webapi/account/users/secure/webEncryptLogin").
            then().
                    log().ifError().
                    assertThat().
                    statusCode(200);

Questions:问题:

  1. Anything wrong with the code?代码有什么问题吗?
  2. How to specify raw data with rest assured?如何用 rest 确定原始数据?
  3. How to extract access token into string?如何将访问令牌提取到字符串中?

Please help.请帮忙。 Thanks.谢谢。

Change params to body() method将参数更改为 body() 方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM