通过代理服务器在Android 2.3 HTTPS中调用SSL Broken PIPE

时间:2012-05-09 18:15:40

标签: android ssl https proxy

我经历过所有可以找到的相关帖子,试图找到最底层并且不清楚 - 希望有人能把我从痛苦中解脱出来......

我试图让Android 2.3通过代理服务器通过HTTPS进行POST。这段代码在2.2上通过代理完美地运行,并且在不通过代理时使用HTTPS完美地在2.2和2.3上运行,并且在所有情况下(2.2和2.3)我可以通过代理通过HTTPS获取。它只是2.3 POST通过代理使用HTTPS似乎是问题。我得到了可怕的“破管”错误。当我尝试从连接读取输入流响应时抛出错误 - 可能是因为TCP套接字已在我的流下面关闭。我已经尝试了我能想到的一切,包括使用Connection和Proxy-connection标头(设置为close和keep-alive)和设置大的readTimeout数字(30秒)。从我无情的谷歌搜索,我可以看到Android 2.3上存在已知的SSL问题,但我似乎无法找到任何暗示POST可能成为问题的原因。 Wireshark已经取得了一些成果,但鉴于这是SSL,如果只是有点棘手来解决这个问题。

有人看起来如此吗?我正在使用HttpsURLConnection作为各种帖子建议这比AndroidHttpClient更稳定。这是我的代码......任何帮助都是无价之宝。感谢

urlConnection.setSSLSocketFactory(factory);     
urlConnection.setHostnameVerifier(new AllowAllHostnameVerifier() );

String dateText = "{\"loopParam\":\"" + String.valueOf(d.getHours()) + ":" +   String.valueOf(d.getMinutes()) + ":" + String.valueOf(d.getSeconds())  + "\"}";
                txtOutput.setText("Sending " +     String.valueOf(dateText.length() ) + " bytes of JSON to /pulse/loop" );

urlConnection.addRequestProperty("Content-type", "application/json");
                urlConnection.setDoOutput(true);
urlConnection.setRequestProperty("Proxy-connection", "Keep-Alive");
urlConnection.setRequestProperty("Connection", "Keep-Alive");
                urlConnection.setDoInput(true);
                urlConnection.setUseCaches(false);
                urlConnection.setReadTimeout(30000);
                urlConnection.setRequestMethod("POST");
                DataOutputStream dataOut = new     DataOutputStream(urlConnection.getOutputStream());
                dataOut.writeBytes(dateText);
                dataOut.flush();

BufferedReader bufIn = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
            String sResponse;
            StringBuilder s = new StringBuilder();

         //bufIn is null as error as closed urlcConnection
            while ((sResponse = bufIn.readLine()) != null) {
                s = s.append(sResponse);
            }

错误详情:     08-May-12 09:09:51 SsliferSnifferActivity通过代理信息连接

08-May-12 09:09:54 SsliferSnifferActivity javax.net.ssl.SSLException: Write error: ssl=0x2d42b8: I/O error during system call, Broken pipe
at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_write(Native Method)
at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:837)
at java.io.OutputStream.write(OutputStream.java:80)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.writeRequestHeaders(HttpURLConnectionImpl.java:799)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.retrieveResponse(HttpURLConnectionImpl.java:1028)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:726)
at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:110)
at uk.co.flurrished.sslifersniffer.SslifersnifferActivity.makeRequest(SslifersnifferActivity.java:236)
at uk.co.flurrished.sslifersniffer.SslifersnifferActivity.access$2(SslifersnifferActivity.java:148)
at uk.co.flurrished.sslifersniffer.SslifersnifferActivity$2.onClick(SslifersnifferActivity.java:76)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3822)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)

编辑:这看起来像是由服务器引发400(错误请求)并关闭管道引起的。什么是关于ANdroid 2.3,当通过导致400的代理路由时添加额外的内容?

1 个答案:

答案 0 :(得分:1)

'断管'只有一个含义。您已写入已被另一端关闭的连接。你确定同伴真的在说SSL吗?