日期:2014-05-19  浏览次数:20766 次

请问一个Connect Time out的问题,谢谢!
java写了一个程序,向某https网站发送POST,
但报错:
message:POST cbmui/en_US/themes/excel/index.htm
Host: 10.63.11.34
Accept: */*
Content-Type: application/x-www-form-urlencoded
Content-Length: 0


java.net.ConnectException: Connection timed out: connect
Exception in thread "main" java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:559)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.<init>(SSLSocketImpl.java:360)
at com.sun.net.ssl.internal.ssl.SSLSocketFactoryImpl.createSocket(SSLSocketFactoryImpl.java:71)
at HttpPostTest_Socket.main(HttpPostTest_Socket.java:41)

好急啊。。。
代码如下,弄了一天,不确定是什么原因,麻烦大家,谢谢!
Java code
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.Socket;
import java.net.URL;
import java.net.URLConnection;
import java.security.GeneralSecurityException;
import java.security.SecureRandom;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import org.apache.commons.logging.*;

public class HttpPostTest_Socket {

    /**
     * @param args
     * @throws Exception 
     */
    public static void main(String[] args) throws Exception {
        String url="https://10.63.11.34/cbmui/en_US/themes/excel/index.htm";  
              SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory.getDefault();  
              String reqMsg= getFirestRequestMsg(url);  
              Socket socket=null;  
              try {  
                   System.out.println("message:"+reqMsg);  
                    socket = ssf.createSocket("10.63.11.43", 443);     
                    PrintWriter tOut = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())));  
                     tOut.write(reqMsg);  
                      tOut.println();  
                     tOut.flush();  
                    System.out.println("Message sent successfully.");  
          
                     BufferedReader tIn = new BufferedReader(new InputStreamReader(socket.getInputStream()));  
                     String tLine = null;  
                    StringBuilder sb=new StringBuilder();  
                      while ((tLine = tIn.readLine()) != null) {  
                       sb.append(tLine).append("\n");  
                      }  
                      System.out.println("Response:"+sb.toString());  
                    
                }