无法从客户端网络中发布到URL

时间:2015-12-29 14:51:47

标签: java apache-commons-httpclient

PostMethod post = new PostMethod(strURL);
try {
  post.setRequestEntity(new InputStreamRequestEntity(new FileInputStream(input), input.length()));
  post.setRequestHeader("Content-type","text/xml; charset=ISO-8859-1");

  HttpClient httpclient = new HttpClient();
  HostConfiguration config = httpclient.getHostConfiguration();
  config.setProxy("zz.zz.zz.zz", 1111);

  String username = "username";
  String password = "password";
  Credentials credentials = new UsernamePasswordCredentials(username, password);
  AuthScope authScope = new AuthScope("zz.zz.zz.zz", 1111);
  httpclient.getState().setProxyCredentials(authScope, credentials);

  int result = httpclient.executeMethod(post);

当我在客户端网络之外时,上面的代码工作正常。有人可以检查代码中是否有任何错误

Dec 29, 2015 2:34:26 PM org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
INFO: I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect
Dec 29, 2015 2:34:26 PM org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
INFO: Retrying request
java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)

0 个答案:

没有答案