android https ssl协议,Android的SSL HTTPS POST(Android SSL https post)

我见过很多类似的问题在这里,但无法找到解决方案。 我在X10溢价主持一个Web服务的PHP文件。 我买了他们的SSL证书,并可以通过HTTPS访问上的浏览器和iPhone上的应用程序我的网页。 我无法做同样在Android应用程式。

我尝试了许多解决方案,但不断收到SSL错误。 我想这个教程http://www.makeurownrules.com/secure-rest-web-service-mobile-application-android.html ,但我发现

10-04 07:21:57.081: W/System.err(6804): javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x2a1a11a8: Failure in SSL library, usually a protocol error

10-04 07:21:57.081: W/System.err(6804): error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol (external/openssl/ssl/s23_clnt.c:766 0x471f5756:0x00000000)

10-04 07:21:57.091: W/System.err(6804): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:436)

10-04 07:21:57.123: W/System.err(6804): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLInputStream.

10-04 07:21:57.123: W/System.err(6804): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.getInputStream(OpenSSLSocketImpl.java:618)

10-04 07:21:57.123: W/System.err(6804): at org.apache.http.impl.io.SocketInputBuffer.(SocketInputBuffer.java:70)

10-04 07:21:57.131: W/System.err(6804): at org.apache.http.impl.SocketHttpClientConnection.createSessionInputBuffer(SocketHttpClientConnection.java:83)

10-04 07:21:57.131: W/System.err(6804): at org.apache.http.impl.conn.DefaultClientConnection.createSessionInputBuffer(DefaultClientConnection.java:170)

10-04 07:21:57.131: W/System.err(6804): at org.apache.http.impl.SocketHttpClientConnection.bind(SocketHttpClientConnection.java:106)

10-04 07:21:57.131: W/System.err(6804): at org.apache.http.impl.conn.DefaultClientConnection.openCompleted(DefaultClientConnection.java:129)

10-04 07:21:57.131: W/System.err(6804): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:172)

10-04 07:21:57.141: W/System.err(6804): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)

10-04 07:21:57.141: W/System.err(6804): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)

10-04 07:21:57.141: W/System.err(6804): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)

10-04 07:21:57.141: W/System.err(6804): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)

10-04 07:21:57.151: W/System.err(6804): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)

10-04 07:21:57.151: W/System.err(6804): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)

10-04 07:21:57.201: W/System.err(6804): at com.lablabla.parkme.ParkMeActivity.performUpdate(ParkMeActivity.java:233)

10-04 07:21:57.211: W/System.err(6804): at com.lablabla.parkme.ParkMeActivity.access$8(ParkMeActivity.java:220)

10-04 07:21:57.211: W/System.err(6804): at com.lablabla.parkme.ParkMeActivity$3.onClick(ParkMeActivity.java:215)

10-04 07:21:57.211: W/System.err(6804): at android.view.View.performClick(View.java:4084)

10-04 07:21:57.221: W/System.err(6804): at android.view.View$PerformClick.run(View.java:16966)

10-04 07:21:57.221: W/System.err(6804): at android.os.Handler.handleCallback(Handler.java:615)

10-04 07:21:57.221: W/System.err(6804): at android.os.Handler.dispatchMessage(Handler.java:92)

10-04 07:21:57.241: W/System.err(6804): at android.os.Looper.loop(Looper.java:137)

10-04 07:21:57.241: W/System.err(6804): at android.app.ActivityThread.main(ActivityThread.java:4745)

10-04 07:21:57.251: W/System.err(6804): at java.lang.reflect.Method.invokeNative(Native Method)

10-04 07:21:57.251: W/System.err(6804): at java.lang.reflect.Method.invoke(Method.java:511)

10-04 07:21:57.271: W/System.err(6804): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)

10-04 07:21:57.271: W/System.err(6804): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)

10-04 07:21:57.281: W/System.err(6804): at dalvik.system.NativeStart.main(Native Method)

10-04 07:21:57.291: W/System.err(6804): Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x2a1a11a8: Failure in SSL library, usually a protocol error

10-04 07:21:57.291: W/System.err(6804): error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol (external/openssl/ssl/s23_clnt.c:766 0x471f5756:0x00000000)

10-04 07:21:57.311: W/System.err(6804): at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(Native Method)

10-04 07:21:57.311: W/System.err(6804): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:395)

我在这里尝试了其他建议在SO,接受所有证书,因为我在做我自己的web服务的调用,并相信所有证书。

另一件事,我可以在浏览器中,并通过HTTP连接的iPhone应用程序,我的web访问。 但是,当我试图让它在Android中,我收到回包含HTML响应

10-04 07:29:47.662: D/RESULT(6900): instead of REQUEST_URI, we could show absolute URL via:

10-04 07:29:47.662: D/RESULT(6900): http://HTTP_HOST/REQUEST_URI

10-04 07:29:47.662: D/RESULT(6900): but what if its https:// or other protocol?

10-04 07:29:47.662: D/RESULT(6900):

10-04 07:29:47.662: D/RESULT(6900): SERVER_PORT_SECURE doesn't seem to be used

10-04 07:29:47.662: D/RESULT(6900): SERVER_PORT logic would break if they use alternate ports

10-04 07:29:47.662: D/RESULT(6900): -->

10-04 07:29:47.662: D/RESULT(6900):

404 Not Found

有任何想法吗?

谢谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用winhttp库在QT下使用https SSL post数据的示例代码: ```cpp #include <Windows.h> #include <Winhttp.h> #pragma comment(lib, "Winhttp.lib") void postData() { HINTERNET hSession = NULL; HINTERNET hConnect = NULL; HINTERNET hRequest = NULL; DWORD dwSize = 0; DWORD dwDownloaded = 0; LPSTR pszOutBuffer; BOOL bResults = FALSE; // Initialize WinHTTP session hSession = WinHttpOpen(L"WinHTTP Example/1.0", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0); if (!hSession) { qDebug() << "WinHttpOpen failed!" << GetLastError(); goto cleanup; } // Specify an HTTPS server hConnect = WinHttpConnect(hSession, L"www.example.com", INTERNET_DEFAULT_HTTPS_PORT, 0); if (!hConnect) { qDebug() << "WinHttpConnect failed!" << GetLastError(); goto cleanup; } // Create an HTTPS request hRequest = WinHttpOpenRequest(hConnect, L"POST", L"/post", NULL, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, WINHTTP_FLAG_SECURE); if (!hRequest) { qDebug() << "WinHttpOpenRequest failed!" << GetLastError(); goto cleanup; } // Set request headers LPCWSTR pszHeaders = L"Content-Type: application/x-www-form-urlencoded\r\n"; bResults = WinHttpAddRequestHeaders(hRequest, pszHeaders, (DWORD)-1L, WINHTTP_ADDREQ_FLAG_ADD); if (!bResults) { qDebug() << "WinHttpAddRequestHeaders failed!" << GetLastError(); goto cleanup; } // Send the POST request LPCWSTR pszData = L"key1=value1&key2=value2"; bResults = WinHttpSendRequest(hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, (LPVOID)pszData, wcslen(pszData), wcslen(pszData), 0); if (!bResults) { qDebug() << "WinHttpSendRequest failed!" << GetLastError(); goto cleanup; } // Receive response from the server bResults = WinHttpReceiveResponse(hRequest, NULL); if (!bResults) { qDebug() << "WinHttpReceiveResponse failed!" << GetLastError(); goto cleanup; } // Read the server's response do { // Check for available data dwSize = 0; if (!WinHttpQueryDataAvailable(hRequest, &dwSize)) { qDebug() << "WinHttpQueryDataAvailable failed!" << GetLastError(); goto cleanup; } // Allocate space for the buffer pszOutBuffer = new char[dwSize + 1]; if (!pszOutBuffer) { qDebug() << "Out of memory!"; goto cleanup; } // Read the data ZeroMemory(pszOutBuffer, dwSize + 1); if (!WinHttpReadData(hRequest, (LPVOID)pszOutBuffer, dwSize, &dwDownloaded)) { qDebug() << "WinHttpReadData failed!" << GetLastError(); goto cleanup; } // Print the response to the console qDebug() << QString::fromLocal8Bit(pszOutBuffer); // Free the memory allocated to the buffer delete[] pszOutBuffer; } while (dwSize > 0); cleanup: // Close any open handles if (hRequest) WinHttpCloseHandle(hRequest); if (hConnect) WinHttpCloseHandle(hConnect); if (hSession) WinHttpCloseHandle(hSession); } ``` 以上代码中,我们首先使用WinHttpOpen函数创建一个WinHTTP会话,然后使用WinHttpConnect函数连接到指定的HTTPS服务器。接着,我们使用WinHttpOpenRequest函数创建一个HTTPS请求,并使用WinHttpAddRequestHeaders函数设置请求头。然后,我们使用WinHttpSendRequest函数发送POST请求,并使用WinHttpReceiveResponse函数接收服务器的响应。最后,我们使用WinHttpQueryDataAvailable函数查询是否有可用的数据,使用WinHttpReadData函数读取服务器的响应,并使用qDebug打印到控制台上。注意,我们使用了QString::fromLocal8Bit函数将服务器的响应从char *转换为QString。最后,我们使用WinHttpCloseHandle函数关闭所有打开的句柄。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值