我编写了一个使用RestAssured连接到Jira并获取Session ID的脚本。以下是我的代码。
public void getJIRACookieTest(){
System.setProperty("https.proxyHost", "Host");
System.setProperty("https.proxyPort", "PortNo");
System.setProperty("https.proxyUserName","UserName");
System.setProperty("https.proxyPassword","Password");
Response res = given().header("Content-Type","application/json").
when().
body("{\"username\":\"test\",\"password\":\"test\"}").
post("https://jira_url/rest/auth/1/session").
then().extract().response();
System.out.println(res.prettyPrint().toString());
}
这里收到未知的主机错误消息。
然后我尝试了Postman,它完美地工作。我刚刚选择了没有身份验证,Content-Type作为applicatio / json和body用户详细信息
{\"username\":\"test\",\"password\":\"test\"}
在邮递员。
我不确定为什么在尝试使用RestAssured时会遇到未知的主机。
非常感谢您的帮助。
谢谢, 纳伦德拉
答案 0 :(得分:0)
根据您的评论我收集到您使用Postman连接无代理服务器,这样做有效。
您正在RestAssured测试中设置HTTPS代理:
System.setProperty("https.proxyHost", "Host");
System.setProperty("https.proxyPort", "PortNo");
System.setProperty("https.proxyUserName","UserName");
System.setProperty("https.proxyPassword","Password");
从测试中删除这些行后你应该没问题。