我无法通过代理设置访问网址

时间:2014-01-08 07:10:30

标签: java proxy jdk1.5

我尝试通过代理设置访问网址,但无法建立连接。 我试图从谷歌和现有的stackoverflow获得解决方案,但任何事情都不适合我。

IDE- Netbeans

Java-1.5

这是我正在尝试的代码

           HttpClient client = new HttpClient();
            client.getHostConfiguration().setProxy(proxyIp, Integer.parseInt(proxyPort));
            //client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("", ""));
            PostMethod postMethod = new PostMethod(meterConfigXml);
            postMethod.setParameter("u", userName);
            postMethod.setParameter("p", password);
            int statusCode = client.executeMethod(postMethod);

但它给出了例外。

 HttpMethodDirector - Closing the connection.
INFO  2013-12-30 16:49:48,218 [Thread-2] : HttpMethodDirector - I/O exception (java.net.SocketException) caught when processing request: Malformed reply from SOCKS server
DEBUG 2013-12-30 16:49:48,218 [Thread-2] : HttpMethodDirector - Malformed reply from SOCKS server
java.net.SocketException: Malformed reply from SOCKS server
    at java.net.SocksSocketImpl.readSocksReply(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:79)
    at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:121)
    at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:706)
    at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:386)
    at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
    at eltrack.src.MeterThread.saveXMLFile(Unknown Source)
    at eltrack.src.MeterThread.startProcess(Unknown Source)
    at eltrack.src.Synch.run(Synch.java:124)
    at java.lang.Thread.run(Unknown Source)
INFO  2013-12-30 16:49:48,218 [Thread-2] : HttpMethodDirector - Retrying request
DEBUG 2013-12-30 16:49:48,218 [Thread-2] : HttpConnection - Open connection to 192.168.0.3:808
DEBUG 2013-12-30 16:50:05,421 [AWT-EventQueue-0] : HttpMethodDirector - Closing the connection.
INFO  2013-12-30 16:50:05,421 [AWT-EventQueue-0] : HttpMethodDirector - I/O exception (java.net.SocketException) caught when processing request: Malformed reply from SOCKS server
DEBUG 2013-12-30 16:50:05,421 [AWT-EventQueue-0] : HttpMethodDirector - Malformed reply from SOCKS server
java.net.SocketException: Malformed reply from SOCKS server
    at java.net.SocksSocketImpl.readSocksReply(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:79)
    at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:121)
    at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:706)
    at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:386)
    at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
    at eltrack.src.PostSync.init(PostSync.java:48)
    at eltrack.EltrackView.startDataPosting(EltrackView.java:367)
    at eltrack.EltrackView.<init>(EltrackView.java:36)
    at eltrack.EltrackApp.startup(EltrackApp.java:19)
    at org.jdesktop.application.Application$1.run(Application.java:171)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

1 个答案:

答案 0 :(得分:0)

请参阅以下链接,了解HTTPClient中的代理配置:

Common HTTPclient and proxy Apache HttpClient 4.1 - Proxy Settings