简体   繁体   English

通过代理在Android 2.3 HTTPS调用中SSL断开的PIPE

[英]SSL Broken PIPE in Android 2.3 HTTPS call over a Proxy

I've been through every related post I can find trying to get to the bottom of this and am no clearer - hoping someone can put me out of my misery… 我遍历了所有相关的帖子,我试图找到最底层的内容,而且还不明确-希望有人可以让我摆脱困境。

I am trying to get Android 2.3 to POST over HTTPS via a Proxy. 我正在尝试使Android 2.3通过代理通过HTTPS进行POST。 This code works perfectly on 2.2 through a proxy, and perfectly on both 2.2 and 2.3 using HTTPS when not going through a proxy, and in all cases (2.2 and 2.3) i can GET over HTTPS through a proxy. 此代码可通过代理在2.2上完美运行,而在不通过代理的情况下使用HTTPS可在2.2和2.3上完美运行,并且在所有情况下(2.2和2.3),我都可以通过代理通过HTTPS进行获取。 Its just 2.3 POST using HTTPS through a proxy that seems to be the issue. 通过代理使用HTTPS的2.3 POST似乎是问题所在。 I get the dreaded "broken pipe" error. 我收到了可怕的“断管”错误。 The error is thrown when I try and read the inputstream response from the connection - presumably because the TCP socket has been closed underneath my stream. 当我尝试从连接中读取inputstream响应时,抛出该错误-可能是因为TCP套接字已在我的流下方关闭。 I've tried everything I can think of, including using Connection and Proxy-connection headers (setting to both close and keep-alive) and setting big readTimeout numbers (30 seconds). 我已经尝试了所有可以想到的方法,包括使用Connection和Proxy-connection标头(设置为close和keep-alive)以及设置较大的readTimeout数字(30秒)。 From my relentless googling, I can see there are known issues with SSL on Android 2.3, but I can't seem to find anything that suggests why the POST might be an issue. 通过不懈的谷歌搜索,我可以看到Android 2.3上存在SSL的已知问题,但是我似乎找不到任何迹象表明POST可能是一个问题。 Wireshark has yielded some results, but given this is SSL if just a little bit tricky to get to the issue. Wireshark已经产生了一些结果,但是鉴于此问题有些棘手,因此使用SSL。

Has anyone seem this. 有没有人看起来如此。 I'm using HttpsURLConnection as various posts suggest this is more stable that AndroidHttpClient. 我正在使用HttpsURLConnection,因为各种帖子都表明这比AndroidHttpClient更稳定。 Here is my code…any help at all invaluable. 这是我的代码……任何帮助都是无价的。 Thanks 谢谢

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);
            }

Error details: 08-May-12 09:09:51 SsliferSnifferActivity Connecting through proxy INFO 错误详细信息:08-May-12 09:09:51 SsliferSnifferActivity通过代理INFO连接

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)

EDIT : This looks like it is being caused by the server raising a 400 (Bad Request) and closing the pipe. 编辑:这似乎是由服务器引发400(错误请求)并关闭管道引起的。 What is it about ANdroid 2.3 that is adding extra content when routed through a proxy that causes the 400? 当通过导致400的代理路由时,ANdroid 2.3增加了额外的内容是什么?

'Broken pipe' has exactly one meaning. “折断的管道”只有一个含义。 You have written to a connection that has already been closed by the other end. 您已写入另一端已关闭的连接。 Are you sure the peer is really speaking SSL? 您确定对等方确实在说SSL吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM