简体   繁体   中英

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. Hope someone can help.

In postman, i must specify the username and password using raw approach. It will fail on form-data. How to specify raw data in rest-assured?

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:

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?
  3. How to extract access token into string?

Please help. Thanks.

Change params to body() method

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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