Java 使用RestAssured时出现400错误请求错误

Java 使用RestAssured时出现400错误请求错误,java,postman,rest-assured,Java,Postman,Rest Assured,我在InteliJ/Java/restasured中收到一个400错误的POST请求,但在Postman中没有,所以有人能告诉我哪里出错了吗 第一邮递员 Endpoint: https://xxxxxx.auth.us-east-2.amazoncognito.com/oauth2/token 我的身体参数是 client_id anvalidid client_secret shhhhitisasecret scope https://xxxxx

我在InteliJ/Java/restasured中收到一个400错误的POST请求,但在Postman中没有,所以有人能告诉我哪里出错了吗 第一邮递员

Endpoint: https://xxxxxx.auth.us-east-2.amazoncognito.com/oauth2/token

我的身体参数是

client_id       anvalidid
client_secret   shhhhitisasecret    
scope           https://xxxxxx.auth.us-east-2.amazoncognito.com/read    
grant_type      client_credentials
现在,当我发布这篇文章时,我得到了200条回复和一个不错的新访问令牌。 当我在Java/RestAssured中尝试同样的方法时,我得到一个400错误的请求错误,这就是我发布的内容

Endpoint: https://xxxxxx.auth.us-east-2.amazoncognito.com/oauth2/token
身体

每次运行这个程序,我都会收到HTTP/1.1400错误的请求错误,我不知道为什么。 谁能看出我哪里做错了吗。 提前谢谢

下面是返回的标题

Date=Thu, 03 Jun 2021 10:45:55 GMT
Content-Type=application/json;charset=UTF-8
Transfer-Encoding=chunked
Connection=keep-alive
Set-Cookie=XSRF-TOKEN=093edd16-255e-42ad-9f11-be84cd56c5dc; Path=/; Secure; HttpOnly; SameSite=Lax
x-amz-cognito-request-id=4c91be06-9d0b-47d9-997e-f292eee61650
X-Application-Context=application:prod:8443
X-Content-Type-Options=nosniff
X-XSS-Protection=1; mode=block
Cache-Control=no-cache, no-store, max-age=0, must-revalidate
Pragma=no-cache
Expires=0
Strict-Transport-Security=max-age=31536000 ; includeSubDomains
X-Frame-Options=DENY
Server=Server
还有饼干

XSRF-TOKEN=093edd16-255e-42ad-9f11-be84cd56c5dc;Path=/;Secure;HttpOnly

嗯,我做了一些调查,并设法找到了一个解决方案,如下所示

Response response = RestAssured
        .given()
        .header("Content-Type", "application/x-www-form-urlencoded")
        .formParam("client_id", "clientId")
        .formParam("client_secret", "clientSecret")
        .formParam("scope", "https://scope.etc")
        .formParam("grant_type", "client_credentials")
        .request()
        .post(settingsRepository.getSetting("cognito.url.base"));
活到老学到老

Response response = RestAssured
        .given()
        .header("Content-Type", "application/x-www-form-urlencoded")
        .formParam("client_id", "clientId")
        .formParam("client_secret", "clientSecret")
        .formParam("scope", "https://scope.etc")
        .formParam("grant_type", "client_credentials")
        .request()
        .post(settingsRepository.getSetting("cognito.url.base"));