Not able to send API requests from eclipse/Intellij

Im trying to send a get request to an api using eclipse or intellij as part of a test using java/junit and the rest assured frame work.

Each request fails, with the following message

Mar 13, 2018 1:29:56 PM org.apache.http.impl.client.DefaultHttpClient tryConnect INFO: I/O exception (java.net.SocketException) caught when connecting to {s}->http://swapi.co:443: Connection reset

By the way, im attempting this on my work machine/network which uses a proxy

I am able to send the same request manually using postman and this works fine so I dont think there is a problem at the server end.

Does anyone know if there are some settings that i need to change in my ide in order to get this working correctly?

for reference this is the code im trying to run:

@Test

public void canGetLuke(){
    given().relaxedHTTPSValidation().
    when().get("http://swapi.co/api/people/1/?format=json").
            then().
            assertThat().
            body("name",
                    equalTo("Luke Skywalker"));

    }

in addition, these are the network connection settigns in eclipse

Under Run configurations or Debug configurations, in the Arguments tab, you can add the proxy settings that the VM will use. Try setting the following params with your proxy host and port:

-Dhttp.proxyHost="your.proxy.com"

-Dhttp.proxyPort="8080"

Generate Client-side XML-Java binding. To develop well-formed and valid requests from your client to the target Web service, you need to know the available methods of the Web service, the data types it uses, the interface to the service, the acceptable format of requests, the format of generated responses, etc.

I ended up one of the doing one the following:

Add proxy to a method:

@Test

public void canGetLuke(){
given().proxy("my.proxy.com", 8080).
when().get("https://swapi.co/api/people/1/?format=json").
        then().
        assertThat().
        body("name",
                equalTo("Luke Skywalker"));

}

or use the proxy settings in an @Before method like so:

@Before
        public void setProxy() {

    proxy("my.proxy.com", 8080);

}

Both of the above approaches worked for me Also had to send the request as https

This plugin is bundled with IntelliJ IDEA and enabled by default. At a module level, the service development support can be enabled when creating a project, adding a new module to an existing project, and also for an existing module.

To extend @JPinzon01's answer, you may need to set HTTP and HTTPS settings

HTTP

-Dhttp.proxyHost="your.proxy.com"
-Dhttp.proxyPort="8080"

HTTPS

-Dhttps.proxyHost="your.proxy.com"
-Dhttps.proxyPort="8080"

When you execute the request, you can choose between defined environments and thus send it to a specific host: The selected environment will be used as the default one when Viewing a structure of the request, opening the request in the browser , executing the request , and creating a run/debug configuration for it.

If not, activate it in the Plugins page of the Settings dialog. There are two main use cases when you need to compose and run requests to a RESTful Web service: When you have developed and deployed a RESTful Web service and want to make sure it works as expected, is accessible in compliance with the specification, and responds correctly.

Scratch files are not stored inside a project, so IntelliJ IDEA can modify them and add additional information about the request. When an HTTP request is executed from a scratch file, the link to the response output file is added below the request and at the top of the requests history file.

If we're using Eclipse IDE, we need to get the Lombok jar first. The latest version is located on Maven Central. For our example, we're using lombok-1.18.4.jar. Next, we can run the jar via java -jar command and an installer UI will open. This tries to automatically detect all available Eclipse installations, but it's also possible to specify

Comments
  • Try connecting using HTTPS
  • I forgot to mention that both HTTP and HTTPS do not work, resulting in the same message detailed in my original post
  • The IDE settings for its network usage do not affect your application.
  • Hi Unfortunately this did not work. The solution i found was to add my proxy settings, either in a given statement or in and @Before method