Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法获取rest assured中localhost url为的令牌_Java_Post_Localhost_Rest Assured - Fatal编程技术网

Java 无法获取rest assured中localhost url为的令牌

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

我不擅长使用rest-assured进行测试。在“邮递员”中,它工作正常,可以返回令牌。但是,当我使用rest-assured获取令牌时,它在状态代码中返回404,在主体响应中返回“error”:“unauthorized”。 这是我的密码

 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状态代码