HTTP URL 连接超时

HTTP URL Connection Timeout

当我在浏览器中点击以下 URL 时,它工作正常:

http://62.215.226.164/fccsms_P.aspx?UID=something&P=something&S=InfoText&G=96567771404&M=hello&L=E

但是当我尝试使用以下 java 代码点击 URL 时,它不起作用:

try {
        URL url = new URL(null, "http://62.215.226.164/fccsms_P.aspx?", new sun.net.www.protocol.https.Handler());
        HttpsURLConnection con = (HttpsURLConnection) url.openConnection();

        con.setRequestMethod("POST");

        String urlParameters="UID=something&P=something=InfoText&G=96567771404&M=hello&L=E";
        // Send post request
        con.setDoOutput(true);
        DataOutputStream wr = new DataOutputStream(con.getOutputStream());
        wr.writeBytes(urlParameters);
        wr.flush();
        wr.close();

        int responseCode = con.getResponseCode();
        System.out.println("\nSending 'POST' request to URL : " + url);
        System.out.println("Post parameters : " + urlParameters);
        System.out.println("Response Code : " + responseCode);

        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String inputLine;
        StringBuffer response = new StringBuffer();

        while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
        }
        in.close();
    } 
     catch(Exception e) {
        System.err.println("Error: "+e.getMessage());   
    }

代码有什么问题吗?

您正在通过 HttpsURLConnection 发送 HTTP url。所以它的制造问题。只需更改您的前两行。您将获得正确的输出。

URL url = new URL("http://62.215.226.164/fccsms_P.aspx");
HttpURLConnection con = (HttpURLConnection) url.openConnection();

您需要先修正您的请求参数:

url参数="UID=something&P=something=InfoText&G=96567771404&M=hello&L=E";

请post此处的异常堆栈跟踪可以更好地帮助您。