LTE/蜂窝网络上的java连接重置

问题描述

private void apacheClient(String path,String data) { DefaultHttpClient httpClient = new DefaultHttpClient();

    try {
        //Define a postRequest request
        HttpPost postRequest = new HttpPost(path);

        //Set the API media type in http content-type header
        postRequest.addHeader("content-type","application/xml");
        //Set the request post body
        StringEntity userEntity = new StringEntity(data);
        postRequest.setEntity(userEntity);

        //Send the request; It will immediately return the response in HttpResponse object if any
        HttpResponse response = httpClient.execute(postRequest);
        //verify the valid error code first
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != 201) {
            throw new RuntimeException("Failed with HTTP error code : " + statusCode);
        }

        InputStream is = response.getEntity().getContent(); // Create an InputStream with the response
        BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) // Read line by line
            sb.append(line + "\n");

        String resstring = sb.toString(); // Result is here
        System.out.println("===Response ==> " + resstring);

        aiResponse = gson.fromJson(resstring,AIResponse.class);
        if (aiResponse.getErrors().size() == 0) {
            System.out.println("Sent logs to AI successfully");
        } else {
            System.out.println("Application Insight connectivity issue");
        }
        sb = null;
        is = null;
    } catch (Exception e) {
    } finally {
        //Important: Close the connect
        httpClient.getConnectionManager().shutdown();
        httpClient = null;
    }
}

我使用上面的代码进行 HTTP 连接。使用 Wi-Fi 和以太网,它工作得非常好,但使用蜂窝/LTE,它会出现以下问题,任何人都可以帮我解决这个问题

javax.net.ssl.SSLException:连接重置 在 org.openjsse.sun.security.ssl.Alert.createSSLException(Alert.java:127) 在 org.openjsse.sun.security.ssl.TransportContext.fatal(TransportContext.java:320) 在 org.openjsse.sun.security.ssl.TransportContext.fatal(TransportContext.java:263) 在 org.openjsse.sun.security.ssl.TransportContext.fatal(TransportContext.java:258) 在 org.openjsse.sun.security.ssl.SSLTransport.decode(SSLTransport.java:137) 在 org.openjsse.sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1152) 在 org.openjsse.sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1063) 在 org.openjsse.sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:402) 在 sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559) 在 sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185) 在 sun.net.www.protocol.http.HttpURLConnection.getoutputStream0(HttpURLConnection.java:1334) 在 sun.net.www.protocol.http.HttpURLConnection.getoutputStream(HttpURLConnection.java:1309) 在 sun.net.www.protocol.https.HttpsURLConnectionImpl.getoutputStream(HttpsURLConnectionImpl.java:259)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)