I need to make 700 requests for various json. For example, if I make one of these requests, the response takes 12 seconds. Accordingly, all 700 requests will take about 2 hours.
I used the HtmlUnit libraries (net.sourceforge.htmlunit) and rest-assured (com.jayway.restassured)
Example code on HtmlUnit for two queries:
WebClient client = new WebClient();
Page page = client.getPage("https://api.privatbank.ua/p24api/exchange_rates?json&date=01.12.2014");
WebResponse response = page.getWebResponse();
Page page2 = client.getPage("https://api.privatbank.ua/p24api/exchange_rates?json&date=02.12.2014");
WebResponse response2 = page2.getWebResponse();
System.out.println(response.getContentAsString());
System.out.println(response2.getContentAsString());
Example code on rest-assured for two requests:
String sURL ="https://api.privatbank.ua/p24api/exchange_rates?json";
Map<String, String> queryParms= new HashMap<>();
queryParms.put("date", String.valueOf("01.12.2014"));
Response response = RestAssured.expect().statusCode(200).given()
.queryParameters(queryParms)
.log().all()
.when()
.get(sURL)
.then().assertThat()
.log().all()
.extract().response();
System.out.println(response.getBody().asString());
queryParms.put("date", String.valueOf("02.12.2014"));
Response response = RestAssured.expect().statusCode(200).given()
.queryParameters(queryParms)
.log().all()
.when()
.get(sURL)
.then().assertThat()
.log().all()
.extract().response();
System.out.println(response.getBody().asString());
On the other hand, if I make a request through the browser to the same addresses, for example via Chrome, then the request occurs instantly.
How on Java do the same fast queries?
Aucun commentaire:
Enregistrer un commentaire