Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
570 views
in Technique[技术] by (71.8m points)

jira - cannot authorize using Rest-Assured

400 error cannot understand where is mistake in code I used Rest-assured documentation https://www.toolsqa.com/rest-assured/post-request-using-rest-assured/

Please help with this question

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");
    }
}
question from:https://stackoverflow.com/questions/66049665/cannot-authorize-using-rest-assured

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

First of all, always try opening the end point url in new tab of browser, if it doesn't give any error then, it is an indication that we can use it. If browser displays something like "This site can't be reached", then it is not a valid end point or server is not up and running for respective end point.

In case of toolsqa website, in starting few pages endpoints are not working. I sent a message to Virender to look into this issue, but unfortunately no response.

I suggest you to learn rest assured from makeseleniumeasy website as per my personal experience.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...