简体   繁体   中英

Rest-assured requests not working

I am using Rest-Assured to test my Rest API. the webservice seems to be running ok, since running

    curl -u "admin:admin" http://localhost:8888/users/

i get my Users as json.

then, when trying a simple request with Rest-Assured

 RestAssured.authentication = basic("admin", "admin");

  expect().statusCode(200).when().get("http://localhost:8888/users/");

gives me the output

    Exception in thread "main" org.apache.http.conn.HttpHostConnectException: Connection to http://localhost:8888 refused
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:158)
…

what can this be?

Solved. Changed from localhost to 127.0.0.1 and it worked. It's kind of odd that both cURL/browser worked with localhost. Guess this might be a routing problem.

Localhost is the default address Rest Assured is sending all requests to. So normally you dont really need to specify it.

This should work:

 RestAssured.authentication = basic("admin", "admin");
 RestAssured.port = 8888
 expect().statusCode(200).when().get("/users");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM