如何解决不能授权使用 Rest-Assured
400 错误无法理解代码错误在哪里 我使用了放心的文档 https://www.toolsqa.com/rest-assured/post-request-using-rest-assured/
请帮忙解决这个问题
package forth;
import org.apache.log4j.BasicConfigurator;
import org.testng.annotations.Test;
import org.testng.Assert;
import io.restassured.RestAssured;
import io.restassured.specification.RequestSpecification;
import io.restassured.response.Response;
import org.json.simple.JSONObject;
public class zero {
@Test
public void RegistrationSuccessful()
{
BasicConfigurator.configure();
RestAssured.baseURI ="url";
RequestSpecification request = RestAssured.given();
JSONObject requestParams = new JSONObject();
requestParams.put("useremail","my login");
requestParams.put("api_token","my token");
request.header("Content-Type","application/json");
request.body(requestParams.toJSONString());
Response response = request.post("/rest/auth/1/session");
int statusCode = response.getStatusCode();
Assert.assertEquals(statusCode,"201");
String successCode = response.jsonPath().get("SuccessCode");
Assert.assertEquals( "Correct Success code was returned",successCode,"OPERATION_SUCCESS");
}
}
解决方法
首先,总是尝试在浏览器的新标签页中打开终点网址,如果没有出现任何错误,则表明我们可以使用它。如果浏览器显示“无法访问此站点”之类的内容,则它不是有效的端点或服务器未针对相应端点启动和运行。
对于 toolsqa 网站,在开始的几个页面中,端点不工作。我向 Virender 发送了消息以调查此问题,但很遗憾没有回复。
根据我的个人经验,建议您到makeseleniumeasy网站学习放心。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。