Reputation: 370
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?
Upvotes: 6
Views: 4709
Reputation: 674
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");
Upvotes: 0
Reputation: 370
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.
Upvotes: 5