【问题标题】:Rest-Assured JIRA Java unable to get Response放心的 JIRA Java 无法获得响应
【发布时间】:2016-09-22 11:22:51
【问题描述】:

请考虑下面的代码,

import org.junit.Test;
import org.omg.CORBA.Request;

import com.jayway.restassured.RestAssured;
import com.jayway.restassured.response.Response;

import static com.jayway.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;

public class App 
{

    @Test
    public void loginAuthentication()
    {

        RestAssured.authentication = basic("username", "password");

        Response resp = given().
            contentType("application/x-www-form-urlencoded").
        when().
            post("https://unitrends.atlassian.net/login?username=Gayatri.londhe&password=GayatriA4");

        System.out.println(resp.prettyPrint());
    }
}

我得到以下回应,

<div class="aui-message error">
     <span class="aui-icon icon-error"/>
     <span class="error" id="error-authentication_failure_invalid_credentials">
        Sorry, we didn't recognize that username and password combination. Please double-check and try again.
     </span>
</div>

如何在放心中使用身份验证,我可以使用 REST-console(chrome 插件)进行休息后请求。 我做错了什么?

我希望能在这方面得到一些帮助。我是放心测试的新手。

【问题讨论】:

    标签: java jira jira-rest-api rest-assured


    【解决方案1】:

    试试这个...

    Response resp = given().
                contentType("application/x-www-form-urlencoded").expect().response().statusCode(200).
                when().
                post("https://unitrends.atlassian.net/login?username=Gayatri.londhe&password=GayatriA4");
    

    如果响应状态为 200,它将获取响应。如果您的服务端点成功返回不是 200,则更改它。

    试试这个

    @BeforeClass
    public void setup() throws org.json.JSONException, IOException {
      //Assigning base url
        RestAssured.baseURI = "https://unitrends.atlassian.net/";
        //Assigning default port
        RestAssured.port = <port>
        RestAssured.basePath = "login";
        RestAssured.config = config().redirect(RedirectConfig.redirectConfig().followRedirects(true).and().allowCircularRedirects(true).maxRedirects(100));
    }
    @Test
    public void testRestServiceAuthentication() {
        //for a get method with basic authorization,its expecting response code 200
        Response res = given().expect().response().statusCode(200).when().post("?username=Gayatri.londhe&password=GayatriA4");
        System.out.println(res.getBody().asString());
    }
    

    【讨论】:

    • 测试运行成功,我想从响应中提取 atl_Token。我该怎么做?
    • 为什么我没有看到这个 api 在 fiddler 上命中?
    • String output = response.getBody().asString(); System.out.println(output); JSONObject obj = new JSONObject(output); String status= String.valueOf(obj.get("&lt;atl_Token&gt;")); } 你可以用这个..那个令牌是作为报头发送的吗?
    • 我正在使用“com.jayway.restassured.RestAssured”这个罐子
    • 您的服务器在本地机器还是远程机器上运行?如果是远程机器,请确保防火墙已关闭。你有没有用任何休息客户端打过端点?分享你的端点是否可以?如果可以,我可以尝试找到原因。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-08
    • 1970-01-01
    • 2017-08-21
    • 2020-08-25
    相关资源
    最近更新 更多