首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >例外:握手失败(Android,在线数据库)

例外:握手失败(Android,在线数据库)
EN

Stack Overflow用户
提问于 2017-08-29 09:36:17
回答 1查看 870关注 0票数 2

因此,我试图将我的应用程序连接到一个数据库中,在教程之后,我发现当我按下“注册”按钮(意思是在awardspace.com上的数据库-mysql数据库中创建一行)时,我总是会收到错误消息:

例外:汉莎失败了。

我安装了浏览器:www.mywebsite.com/Register.php,它运行得很好。

这是register-activity代码和register.php

RegisterActivity:

代码语言:javascript
复制
package com.example.geqwe1.ankle;

import android.content.Context;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class RegisterActivity extends AppCompatActivity {


    EditText email;
    String spinner, Email,Spinner;
    Context ctx=this;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        email = (EditText) findViewById(R.id.email_register);
        spinner = "yolo";
    }

    public void register_register(View v) {
        Email = email.getText().toString();
        BackGround b = new  BackGround();
        b.execute(Email,spinner);
    }

    class BackGround extends AsyncTask<String, String, String> {

        @Override
        protected String doInBackground(String... params) {
            String email = params[0];
            String spinner = params[1];
            String data = "";
            int tmp;

            try{
                URL url = new URL("https://ankle.atwebpages.com/Register.php/");
                String urlParams = "email="+email+"&spinner"+spinner;

                HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
                httpURLConnection.setDoOutput(true);
                OutputStream os = httpURLConnection.getOutputStream();
                os.write(urlParams.getBytes());
                os.flush();
                os.close();
                InputStream is = httpURLConnection.getInputStream();
                while((tmp=is.read())!= -1){
                    data+= (char)tmp;
                }
                is.close();
                httpURLConnection.disconnect();

                return data;

            } catch (MalformedURLException e) {
                e.printStackTrace();
                return  "Exception: "+e.getMessage();
            } catch (IOException e) {
                e.printStackTrace();
                return "Exception: " + e.getMessage();
            }
        }

            @Override
            protected void onPostExecute(String s) {
                if (s.equals("")) {
                    s = "Data saved successfully.";
                }
                Toast.makeText(ctx, s, Toast.LENGTH_LONG).show();
            }
    }
}

Register.php:

代码语言:javascript
复制
<?php
    $con = mysqli_connect("fdb15.awardspace.net", "2432552_db", "mypassword", "2432552_db");

    $user_id = $_POST["user_id"];
    $email = $_POST["email"];
    $gender = $_POST["gender"];
    $sql = "INSERT INTO users_table (user_id, email, gender) VALUES (NULL, '".$email."','".$gender."');";

?>

按下寄存器后的logcat

代码语言:javascript
复制
08-29 14:19:25.968 1661-1706/system_process I/ActivityManager: Killing 3494:com.android.gallery3d/u0a47 (adj 906): empty #17
08-29 14:19:26.058 1661-2063/system_process D/ActivityManager: cleanUpApplicationRecord -- 3494
08-29 14:19:26.100 1396-1428/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 716474 , only wrote 716400
08-29 14:19:26.176 4160-4332/com.example.geqwe1.ankle D/NetworkSecurityConfig: No Network Security Config specified, using platform default
08-29 14:19:26.541 4160-4167/com.example.geqwe1.ankle W/art: Suspending all threads took: 7.465ms
08-29 14:19:26.939 4160-4332/com.example.geqwe1.ankle W/System.err: javax.net.ssl.SSLHandshakeException: Handshake failed
08-29 14:19:26.941 4160-4332/com.example.geqwe1.ankle W/System.err:     at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:429)
08-29 14:19:26.946 4160-4332/com.example.geqwe1.ankle W/System.err:     at com.android.okhttp.Connection.connectTls(Connection.java:235)
08-29 14:19:26.955 4160-4332/com.example.geqwe1.ankle W/System.err:     at com.android.okhttp.Connection.connectSocket(Connection.java:199)
08-29 14:19:26.956 4160-4332/com.example.geqwe1.ankle W/System.err:     at com.android.okhttp.Connection.connect(Connection.java:172)
08-29 14:19:26.956 4160-4332/com.example.geqwe1.ankle W/System.err:     at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:367)
08-29 14:19:26.956 4160-4332/com.example.geqwe1.ankle W/System.err:     at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:130)
08-29 14:19:26.957 4160-4332/com.example.geqwe1.ankle W/System.err:     at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:329)
08-29 14:19:26.957 4160-4332/com.example.geqwe1.ankle W/System.err:     at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:246)
08-29 14:19:26.957 4160-4332/com.example.geqwe1.ankle W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457)
08-29 14:19:26.957 4160-4332/com.example.geqwe1.ankle W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:126)
08-29 14:19:26.958 4160-4332/com.example.geqwe1.ankle W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:257)
08-29 14:19:26.958 4160-4332/com.example.geqwe1.ankle W/System.err:     at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
08-29 14:19:26.958 4160-4332/com.example.geqwe1.ankle W/System.err:     at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java)
08-29 14:19:26.961 4160-4332/com.example.geqwe1.ankle W/System.err:     at com.example.geqwe1.ankle.RegisterActivity$BackGround.doInBackground(RegisterActivity.java:55)
08-29 14:19:26.961 4160-4332/com.example.geqwe1.ankle W/System.err:     at com.example.geqwe1.ankle.RegisterActivity$BackGround.doInBackground(RegisterActivity.java:40)
08-29 14:19:26.961 4160-4332/com.example.geqwe1.ankle W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:305)
08-29 14:19:26.961 4160-4332/com.example.geqwe1.ankle W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
08-29 14:19:26.962 4160-4332/com.example.geqwe1.ankle W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
08-29 14:19:26.968 4160-4332/com.example.geqwe1.ankle W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
08-29 14:19:26.971 4160-4332/com.example.geqwe1.ankle W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
08-29 14:19:26.971 4160-4332/com.example.geqwe1.ankle W/System.err:     at java.lang.Thread.run(Thread.java:761)
08-29 14:19:26.972 4160-4332/com.example.geqwe1.ankle W/System.err:     Suppressed: javax.net.ssl.SSLHandshakeException: Handshake failed
08-29 14:19:26.972 4160-4332/com.example.geqwe1.ankle W/System.err:         ... 21 more
08-29 14:19:26.973 4160-4332/com.example.geqwe1.ankle W/System.err:         Suppressed: javax.net.ssl.SSLHandshakeException: Handshake failed
08-29 14:19:26.991 4160-4332/com.example.geqwe1.ankle W/System.err:             ... 21 more
08-29 14:19:26.994 4160-4332/com.example.geqwe1.ankle W/System.err:         Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xa7220b40: Failure in SSL library, usually a protocol error
08-29 14:19:26.997 4160-4332/com.example.geqwe1.ankle W/System.err: error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER (external/boringssl/src/ssl/tls_record.c:192 0xa4179196:0x00000000)
08-29 14:19:26.998 4160-4332/com.example.geqwe1.ankle W/System.err:     at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
08-29 14:19:26.998 4160-4332/com.example.geqwe1.ankle W/System.err:     at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:357)
08-29 14:19:26.998 4160-4332/com.example.geqwe1.ankle W/System.err:             ... 20 more
08-29 14:19:27.000 4160-4332/com.example.geqwe1.ankle W/System.err:     Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xa7220b40: Failure in SSL library, usually a protocol error
08-29 14:19:27.002 4160-4332/com.example.geqwe1.ankle W/System.err: error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER (external/boringssl/src/ssl/tls_record.c:192 0xa4179196:0x00000000)
08-29 14:19:27.002 4160-4332/com.example.geqwe1.ankle W/System.err:     at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
08-29 14:19:27.002 4160-4332/com.example.geqwe1.ankle W/System.err:     at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:357)
08-29 14:19:27.002 4160-4332/com.example.geqwe1.ankle W/System.err:         ... 20 more
08-29 14:19:27.003 4160-4332/com.example.geqwe1.ankle W/System.err: Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xa7220b40: Failure in SSL library, usually a protocol error
08-29 14:19:27.003 4160-4332/com.example.geqwe1.ankle W/System.err: error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER (external/boringssl/src/ssl/tls_record.c:192 0xa4179196:0x00000000)
08-29 14:19:27.003 4160-4332/com.example.geqwe1.ankle W/System.err:     at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
08-29 14:19:27.003 4160-4332/com.example.geqwe1.ankle W/System.err:     at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:357)
08-29 14:19:27.004 4160-4332/com.example.geqwe1.ankle W/System.err:     ... 20 more
08-29 14:19:27.107 4160-4196/com.example.geqwe1.ankle D/EGL_emulation: eglMakeCurrent: 0xa5fd4e80: ver 3 1 (tinfo 0xa5fcc970)
08-29 14:19:27.126 4160-4196/com.example.geqwe1.ankle E/OpenGLRenderer: Corrupted GPU pixel buffer
08-29 14:19:27.175 2630-4350/com.google.android.gms W/DriveInitializer: Background init thread started
08-29 14:19:27.189 4160-4196/com.example.geqwe1.ankle D/EGL_emulation: eglMakeCurrent: 0xa5fd4e80: ver 3 1 (tinfo 0xa5fcc970)
08-29 14:19:27.689 2630-4350/com.google.android.gms W/DriveInitializer: Background init thread ended
08-29 14:19:29.327 1396-1429/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 1023969 , only wrote 871200
08-29 14:19:30.524 1661-1661/system_process W/WindowManager: Attempted to remove non-existing token: android.os.Binder@91c59c0
08-29 14:19:45.011 1883-2706/com.android.phone I/OmtpVvmCarrierCfgHlpr: OmtpEvent:CONFIG_STATUS_SMS_TIME_OUT
08-29 14:19:45.011 1883-1883/com.android.phone I/RetryPolicy: discarding deferred status: configuration_state=4
08-29 14:19:45.013 1883-1883/com.android.phone D/VvmTaskScheduler: No more tasks, stopping service if no task are added in 5000 millis
08-29 14:19:45.014 1883-1883/com.android.phone D/VvmTaskScheduler: create task:com.android.phone.vvm.omtp.ActivationTask
08-29 14:19:45.014 1883-1883/com.android.phone D/RetryPolicy: retry #2 for com.android.phone.vvm.omtp.ActivationTask@a95c13 queued, executing in 5000
08-29 14:19:45.016 1883-1883/com.android.phone D/VvmTaskScheduler: minimal wait time:4998
08-29 14:19:45.018 1883-1883/com.android.phone D/VvmTaskScheduler: minimal wait time:4996
08-29 14:19:50.017 1883-2706/com.android.phone V/VvmTaskScheduler: executing task com.android.phone.vvm.omtp.ActivationTask@a95c13
08-29 14:19:50.037 1883-2706/com.android.phone I/VvmActivationTask: VVM content provider configured - vvm_type_cvvm
08-29 14:19:50.037 1883-2706/com.android.phone I/OmtpVvmCarrierCfgHlpr: OmtpEvent:CONFIG_ACTIVATING
08-29 14:19:50.057 1883-2706/com.android.phone V/OmtpMessageSender: Sending BINARY sms 'Activate:dt=15' to 122:1808
08-29 14:19:50.072 1883-1883/com.android.phone D/VvmStatusSmsFetcher: Request SMS successfully sent
08-29 14:20:00.025 1762-2002/com.android.systemui E/OpenGLRenderer: Corrupted GPU pixel buffer
08-29 14:20:05.652 3194-3309/com.google.android.talk I/Babel_ConcService: Acquired partial wake lock to keep ConcurrentService alive
08-29 14:20:05.653 3194-3309/com.google.android.talk I/Babel_ConcService: Released partial wake lock as ConcurrentService became idle    
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-30 06:34:28

为了澄清我在评论中的回答,我指出了这些可能导致SSL握手异常的情况。

  • 如果您在logcat中得到了特定的OPENSSL_internal:WRONG_VERSION_NUMBER。当我们将默认端口设置为80时,当访问https服务器将产生此错误时,就会发生这种情况。
  • 如果在logcat中得到特定的TLSV1或任何其他证书名称,则可能是服务器上的SSL证书无效或自签名。您可以在服务器端更改协议,也可以在Android上使用NOSSLFactory进行检查。
  • 或尝试在非SSL服务器上进行ssl连接。

这些是一些一般的案例

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45935605

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档