6

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?

danieltorres
  • 370
  • 2
  • 12

2 Answers2

5

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.

danieltorres
  • 370
  • 2
  • 12
0

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");
Alex Karamfilov
  • 634
  • 1
  • 6
  • 12