I know that there are many questions regarding the Malformed reply from SOCKS server error, which basically indicates the wrong configuration for the proxy.
However, in my case, I use the HTTP system proxy (!) To request a POST with apache httpclient library 4.3.5 (httpcore 4.3.2) as follows:
SystemDefaultRoutePlanner routePlanner = new SystemDefaultRoutePlanner( ProxySelector.getDefault()); CloseableHttpClient httpclient = HttpClients.custom() .setRoutePlanner(routePlanner) .build();
This is what has also been recommended in https://stackoverflow.com/a/330401/ ...
In most cases, this httpclient and the following http httpclient request work very well. However, on one client, it fails with the following log error:
Mrz 05, 2015 10:11:04 AM org.apache.http.impl.execchain.RetryExec execute Information: I/O exception (java.net.SocketException) caught when processing request to {}->http://proxy.local:80->http://my-webservice.tld:80: Malformed reply from SOCKS server Mrz 05, 2015 10:11:04 AM org.apache.http.impl.execchain.RetryExec execute Information: Retrying request to {}->http://proxy.local:80->http://my-webservice.tld:80
LAN proxy settings (in Windows 7) are not configured as SOCKS proxies, but as HTTP proxies! I confirmed this by registering various RoutePlanner and Proxy parameters:
TunnelType: PLAIN TargetHost: http://my-webservice.tld:80 ProxyHost: http://proxy.local:80 ProxyPort: 80 ProxyType: HTTP
However, my POST request is not sent correctly. In proxy files, it looks like this:
2015-03-05 10:11:04 119973 192.168.124.111 0 TCP_ERR_MISS 0 4 unknown - - / - - - - - - PROXIED - - xxx.xxx.xxx.xxx SG-HTTP-Service
This is my uploadFile() method, which uses the mentioned SystemDefaultRoutePlanner and creates and runs HttpPost :
private String uploadFile(File fileToUpload) throws Exception { SystemDefaultRoutePlanner routePlanner = new SystemDefaultRoutePlanner(ProxySelector.getDefault()); CloseableHttpClient httpclient = HttpClients.custom() .setRoutePlanner(routePlanner) .build(); try { HttpPost httppost = new HttpPost(webserviceURL); MultipartEntityBuilder requestEntity = MultipartEntityBuilder.create(); requestEntity.addPart("project", new StringBody(paramProjekt, ContentType.TEXT_PLAIN)); requestEntity.addPart("param1", new StringBody(param1, ContentType.TEXT_PLAIN)); requestEntity.addPart("param2", new StringBody(param2, ContentType.TEXT_PLAIN)); requestEntity.addPart("debug", new StringBody(paramDebug, ContentType.TEXT_PLAIN)); requestEntity.addPart("xmlFile", new FileBody(fileToUpload)); ProgressHttpEntityWrapper.ProgressCallback progressCallback = new ProgressHttpEntityWrapper.ProgressCallback() { @Override public void progress(float progress) { int min = 5; int max = 40; int diff = max - min; gui.updateProgress(min + (int)(diff * progress / 100)); if (progress == 100) { gui.setStep(GUI.STEP.PROCESSING); } } }; httppost.setEntity(new ProgressHttpEntityWrapper(requestEntity.build(), progressCallback)); logger.info("executing request " + httppost.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httppost); try { logger.info("Response Status: " + response.getStatusLine()); HttpEntity resEntity = response.getEntity(); if (resEntity != null) { String responseString = EntityUtils.toString(resEntity); return responseString; } EntityUtils.consume(resEntity); } catch (Exception e) { e.printStackTrace(); return null; } finally { response.close(); } } finally { httpclient.close(); } return null; }
The last thing in my log file is the information about the executing request , but the log of the Response Status: log is never displayed ...
Mrz 05, 2015 10:09:04 AM de.company.product.WebserviceClient.WebserviceClient uploadFile Information: executing request POST http://my-webservice.tld HTTP/1.1 Mrz 05, 2015 10:11:04 AM org.apache.http.impl.execchain.RetryExec execute Information: I/O exception (java.net.SocketException) caught when processing request to {}->http://proxy.local:80->http://my-webservice.tld:80: Malformed reply from SOCKS server Mrz 05, 2015 10:11:04 AM org.apache.http.impl.execchain.RetryExec execute Information: Retrying request to {}->http://proxy.local:80->http://my-webservice.tld:80
Does anyone know why
- error
Malformed reply from SOCKS server displayed if there is an HTTP proxy server defined in the system, and I use the system proxy settings? - how to configure either
httpclient or HttpPost correctly recognize the system parameters of an HTTP proxy server and work well with a proxy server without it?