谁知道如何解决这个问题?
com.android.volley.noconnectionerror:javax.net.SSLHandshakeException:java.security.cert.CertPathVaildatorException:找不到证书路径的信任锚。
implementation 'com.android.volley:volley:1.1.0'
private static String URL_REGIST = "https://192.168.1.126/functions.php";
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL_REGIST,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try{
JSONObject jsonObject = new JSONObject(response);
String success = jsonObject.getString("successs");
//Log.d("123: " , response);
if (success.equals("1")){
Toast.makeText(RegistActivity.this,"Register Success!", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
//Log.e("456: ", response);
Toast.makeText(RegistActivity.this,"Register Error! " + e.toString(), Toast.LENGTH_SHORT).show();
accountloading.setVisibility(View.GONE);
btn_regist.setVisibility(View.VISIBLE);
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(RegistActivity.this,"Register Error! " + error.toString(), Toast.LENGTH_SHORT).show();
accountloading.setVisibility(View.GONE);
btn_regist.setVisibility(View.VISIBLE);
}
})
{
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("lastname", lastname);
params.put("firstname", firstname);
params.put("nickname", nickname);
params.put("password", password);
//params.put("birthday", birthday);
params.put("email", email);
//params.put("phone", phone);
return params;
}
};
我不知道发生了什么。
下面是我的php代码,它可以链接到数据库。但是我不知道会有什么错误。
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$lastname = $_POST['lastname'];
$firstname = $_POST['firstname'];
$nickname = $_POST['nickname'];
$password1 = $_POST['password'];
//$birthday = $_POST['birthday'];
$email = $_POST['email'];
//$phone = $_POST['phone'];
$password1 = password_hash($password1, PASSWORD_DEFAULT);
require_once 'connect.php';
$sql = "INSERT INTO user (lastname, firstname, nickname, password1, email)
VALUES
('$lastname','$firstname', '$nickname', '$password1', '$email')";
//$sql = "INSERT INTO user (lastname, firstname, nickname, password1, birthday, email, phone)
//VALUES
//('$lastname','$firstname', '$nickname', '$password1', '$birthday', '$email', '$phone')";
if (mysqli_query($conn, $sql)){
$result["success"] = "1";
$result["message"] = "Success";
echo json_encode($result);
mysqli_close($conn);
} else {
$result["success"] = "0";
$result["message"] = "Error";
echo json_encode($result);
mysqli_close($conn);
}
}
问题是您正在使用private static String URL_REGIST = "https://192.168.1.126/functions.php";
作为URL。
但是您的本地IP地址192.168.1.126没有有效的SSL证书。要解决此问题,您可以使用http代替https作为您的本地URL。
[请注意,如果您的真实URL具有有效的SSL证书,则在部署到真实服务器时仍应使用https。