1 import java.io.InputStream;
2 import java.lang.System;
4 import org.apache.http.HttpResponse;
5 import org.apache.http.client.methods.HttpPost;
6 import org.apache.http.entity.StringEntity;
7 import org.apache.http.impl.client.HttpClientBuilder;
8 import org.apache.commons.io.IOUtils;
9 import org.apache.http.impl.client.CloseableHttpClient;
11 public class GastonJSClient{
13 public static void main(String[] args) throws Exception{
14 // write your code here
15 String visitPage = "{\n" +
16 " \"name\": \"visit\",\n" +
18 " \"http://www.google.es\"\n" +
21 String renderPage = "{\"name\":\"render\",\"args\":[\"/Users/juan/Downloads/page_image.png\",true,null]}";
22 CloseableHttpClient httpClient = HttpClientBuilder.create().build();
25 HttpPost request = new HttpPost("http://127.0.0.1:8510/v1/api");
26 StringEntity params = new StringEntity(visitPage);
27 request.addHeader("content-type", "application/json");
28 request.setEntity(params);
29 HttpResponse response = httpClient.execute(request);
30 InputStream body = response.getEntity().getContent();
31 String myString = IOUtils.toString(body, "UTF-8");
32 System.out.println(myString);
34 params = new StringEntity(renderPage);
35 request.setEntity(params);
36 response = httpClient.execute(request);
37 body = response.getEntity().getContent();
38 myString = IOUtils.toString(body, "UTF-8");
39 System.out.println(myString);
40 // handle response here...
41 } catch (Exception ex) {
42 // handle exception here
43 System.out.println(ex.toString());