So I'm trying to connect my app with a database and following a tutorial I got to a point that when I press the register button (meaning create a row in the database-mysql database on awardspace.com), I always get the error message:
exception:hanshake failed.
I put on the browser: www.mywebsite.com/Register.php
and it works fine.
Here is the register-activity
code and the register.php
.
RegisterActivity:
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:
<?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 after pressing register
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
Just to clarify my answer in comment, I am pointing out these case which can result SSL Handshake Exception
These are some generic cases there many other cases, you can edit this answer which will help others.
User contributions licensed under CC BY-SA 3.0