Java 无法获取rest assured中localhost url为的令牌
我不擅长使用rest-assured进行测试。在“邮递员”中,它工作正常,可以返回令牌。但是,当我使用rest-assured获取令牌时,它在状态代码中返回404,在主体响应中返回“error”:“unauthorized”。 这是我的密码Java 无法获取rest assured中localhost url为的令牌,java,post,localhost,rest-assured,Java,Post,Localhost,Rest Assured,我不擅长使用rest-assured进行测试。在“邮递员”中,它工作正常,可以返回令牌。但是,当我使用rest-assured获取令牌时,它在状态代码中返回404,在主体响应中返回“error”:“unauthorized”。 这是我的密码 RequestSpecification request = RestAssured.given(); Response res = request //.contentType("application/json&qu
RequestSpecification request = RestAssured.given();
Response res = request
//.contentType("application/json")
.queryParam("username", "uname")
.queryParam("password", "password")
.queryParam("cliend_id", "android")
.queryParam("grant_type", "password")
.queryParam("scope", "trust")
.post("http://localhost:8080/com.abcde.webservices/oauth/token");
System.out.println("Response : "+res.asString());
System.out.println(res.getStatusCode());
我已经尝试使用
RestAssured.baseURI = "http://localhost:8080/com.abcde.webservices";
.....
.post("/oauth/token");
但是仍然无法获得令牌我刚刚意识到我没有在clint\u id中键入它。我键入cliend\u id,它应该是client\u id。更改后一切正常。您没有发布表单正文。使用
formParam
而不是queryParam
。我想让url像localhost:8080/com.abcde.webservices/oauth/token?username=uname&password=password&client\u id=android&grant\u type=password&scope=trust。使用formParam是否有效?那么您应该使用get
queryParam
用于get
,formParam
用于post
。有关详细信息,请参阅。立即获取401状态代码