所以我正在尝试将我的应用程序与数据库连接并按照教程进行操作,当我按下注册按钮(意味着在awardspace.com上的数据库-mysql数据库中创建一行)时,我总是收到错误消息:
例外:hanshake失败。
我放了浏览器:Gemfile
,它运行正常。
以下是www.mywebsite.com/Register.php
代码和register-activity
。
RegisterActivity:
register.php
Register.php:
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();
}
}
}
按下注册后的logcat
<?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."');";
?>
答案 0 :(得分:0)
为了澄清我在评论中的回答,我指出了这些可能导致 SSL握手异常
的案例这些是一些通用案例,还有许多其他情况,您可以编辑这个答案,这将有助于其他人。