我正在使用带有RestAssured框架的TestNG来测试RestAPI。
一旦执行命中httpRequest.request这一行,就会抛出连接超时错误
我是不是漏掉了什么?它没有抛出任何语法错误。
import org.testng.annotations.BeforeMethod;
import static io.restassured.RestAssured.ntlm;
import static io.restassured.RestAssured.basic;
import org.testng.annotations.Test;
import io.restassured.RestAssured;
import io.restassured.http.Method;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
public class RestApi_Incidents {
@BeforeMethod
public void beforeMethod() {
System.out.println("before method");
}
@Test
void GetIncidentAPI(){
try{
RestAssured.baseURI = "https://xxx/api/data/v8.2";
RestAssured.port = 80;
RestAssured.basePath = "/incident";
RestAssured.authentication = basic("userid", "pwd!");
//RestAssured.authentication = ntlm("uid", "pws!", null, "uat");
RequestSpecification httpRequest = RestAssured.given();
Response response =httpRequest.get();
}
catch (Exception ex){
System.out.println(ex.toString());
}
} }
发布于 2019-10-10 05:30:22
请这样使用
RestAssured.baseURI = "https://xxx/api/data/v8.2/";
RestAssured.port = 80;
RestAssured.basePath = "/incidents/resource/HealthCheckApp";
RestAssured.authentication = basic("username", "password");
RestAssured.authentication = ntlm("myuserid", null, null, "uat");
RequestSpecification httpRequest = RestAssured.given();
Response response =httpRequest.get("/DetailsView");发布于 2019-10-10 07:12:37
你可以重构你的协议,如下所示。我无法复制连接超时错误,因为主机在我的本地上不可用
package api.application.zippopotam;
import io.restassured.authentication.AuthenticationScheme;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.internal.http.HTTPBuilder;
import org.testng.annotations.BeforeMethod;
import static io.restassured.RestAssured.ntlm;
import org.testng.annotations.Test;
import io.restassured.RestAssured;
import io.restassured.http.Method;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
public class RestApi_Incidents {
public static RequestSpecification requestSpecification ;
@BeforeMethod
public void beforeMethod() {
System.out.println("before method");
requestSpecification = new RequestSpecBuilder().
setBaseUri("https://xxx/api/data/v8.2/incidents").
setRelaxedHTTPSValidation().
setBasePath("HealthCheckApp/DetailsView").build()
.auth().basic("userid", "pwd!");
}
@Test
void GetIncidentAPI(){
try{
Response aresponse = RestAssured.
given().
spec(requestSpecification).
when().
get().
then().
extract().
response();
System.out.println("before getBody");
String aresponseBody = aresponse.getBody().asString();
System.out.println("response is " + aresponseBody);
}
catch (Exception ex){
System.out.println(ex.toString());
}
}
}输出
获取未知主机预期错误:,因为您提供的主机名不正确

发布于 2019-10-15 18:26:52
请点击下面的链接。我已经用代码解释过了:
https://stackoverflow.com/questions/58343693/timeout-error-in-restassured-whereas-the-service-giving-response-in-postman-soap/58392345#58392345
https://stackoverflow.com/questions/58311927
复制相似问题