public String performPostRequest ( String requestString , String data ) throws IOException { HttpPost request = new HttpPost ( getBaseUrl ( ) + requestString ) ; String json = null ; CloseableHttpClient httpClient = HttpClients . createDefault ( ) ; if ( proxies . size ( ) > 0 ) { // We only check the first proxy for now Proxy myProxy = proxies . get ( 0 ) ; HttpHost proxy = myProxy . getHttpHost ( ) ; RequestConfig config = RequestConfig . custom ( ) . setProxy ( proxy ) . setSocketTimeout ( myProxy . getProxySocketTimeout ( ) ) . setConnectTimeout ( myProxy . getProxyConnectTimeout ( ) ) . setConnectionRequestTimeout ( myProxy . getProxyConnectionRequestTimeout ( ) ) . setProxyPreferredAuthSchemes ( Arrays . asList ( AuthSchemes . BASIC ) ) . build ( ) ; request . setConfig ( config ) ; } try { logger . debug ( "------------------------------------------------" ) ; logger . debug ( "OSS Index POST: " + getBaseUrl ( ) + requestString ) ; logger . debug ( data ) ; logger . debug ( "------------------------------------------------" ) ; request . setEntity ( new StringEntity ( data ) ) ; CloseableHttpResponse response = httpClient . execute ( request ) ; int code = response . getStatusLine ( ) . getStatusCode ( ) ; if ( code < 200 || code > 299 ) { throw new ConnectException ( response . getStatusLine ( ) . getReasonPhrase ( ) + " (" + code + ")" ) ; } json = EntityUtils . toString ( response . getEntity ( ) , "UTF-8" ) ; } catch ( ParseException e ) { throw new IOException ( e ) ; } finally { httpClient . close ( ) ; } return json ; }
Perform the request with the given URL and JSON data .