如何修复android studio中的网络安全配置?

时间:2016-11-01 01:38:58

标签: java php android database android-studio-2.2

我正在尝试将数据插入到webhost中,在我点击之后,我的应用程序将数据插入数据库,然后返回登录页面。但是当我点击注册按钮时我的应用程序没有回到登录页面,数据没有插入,而在logcat它显示 networksecurityconfig 。我该如何解决这个问题?

RegisterRequest.java:

public class RegisterRequest extends StringRequest {
private static final String REGISTER_REQUEST_URL = " https://http://finalproject.16mb.com/public_html/android/Register.php " ;
private Map<String , String> params;

public RegisterRequest(String name , String username ,String password, Response.Listener<String>listener){
    super(Method.POST, REGISTER_REQUEST_URL, listener, null);
    params = new HashMap<>();
    params.put("name", name);
    params.put("username", username);
    params.put("password", password);
}

public Map<String, String> getParams() {
    return params;
}

} 

RegisterActivity.java:

public class RegisterActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);

    final EditText etName = (EditText) findViewById(R.id.etName);
    final EditText etUsername = (EditText) findViewById(R.id.etUsername);
    final EditText etPassword = (EditText) findViewById(R.id.etPassword);

    final Button bRegister = (Button) findViewById(R.id.bRegister);

    bRegister.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View v) {
            final String name = etName.getText().toString();
            final String username = etUsername.getText().toString();
            final String password = etPassword.getText().toString();


            Response.Listener<String> responseListener = new Response.Listener<String>(){
                @Override
                public void onResponse(String response) {
                    try {
                       JSONObject jsonResponse = new JSONObject(response);
                        boolean success = jsonResponse.getBoolean("SUCCESS");



                        if(success){
                            Intent loginintent = new Intent(RegisterActivity.this, LoginActivity.class);
                            RegisterActivity.this.startActivity(loginintent);
                        }else{
                            AlertDialog.Builder builder = new AlertDialog.Builder(RegisterActivity.this);
                            builder.setMessage("Register Failed")
                                    .setNegativeButton("Retry", null)
                                    .create()
                                    .show();
                        }
                    } catch (JSONException e){
                        e.printStackTrace();
                    }
                }
            };

            RegisterRequest registerRequest = new RegisterRequest(name, username, password, responseListener );
            RequestQueue queue = Volley.newRequestQueue(RegisterActivity.this);
            queue.add(registerRequest);
        }
    });
}
}

Register.php:

<?php
$con=mysql_connect("mysql.hostinger.my","u650032727_lgr","5j5unjie0602","   u650032727_final");

$name=$_POST["name"];
$password=$_POST["password"];
$username=$_POST["username"];
$statement= mysqli_prepare($con,"INSERT INTO user(name,username,password) VALUES (?,?,?)");
mysqli_stmt_bind_param($statement,"sss",$name,$username,$password);
mysqli_stmt_execute($statement);

$response = array();
$response = ["SUCCESS"];

echo json_encode($response);
?>

要价较高:

  '11-01 01:24:30.387 3237-3237/com.example.user.loginregister W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
   11-01 01:24:32.480 3237-3237/com.example.user.loginregister W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
   11-01 01:24:33.744 3237-3237/com.example.user.loginregister W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
   11-01 01:24:33.744 3237-3237/com.example.user.loginregister W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
   11-01 01:24:35.202 3237-3264/com.example.user.loginregister D/NetworkSecurityConfig: No Network Security Config specified, using platform default'

在我的http://finalproject.16mb.com/android/Register.php),it中出现了这个错误:

&#39;不推荐使用:mysql_connect():不推荐使用mysql扩展,将来会删除它:在第2行的/home/u650032727/public_html/android/Register.php中使用mysqli或PDO

警告:mysqli_prepare()要求参数1为mysqli,第9行/home/u650032727/public_html/android/Register.php中给出的资源

警告:mysqli_stmt_bind_param()要求参数1为mysqli_stmt,在第10行的/home/u650032727/public_html/android/Register.php中给出为null

警告:mysqli_stmt_execute()要求参数1为mysqli_stmt,在第11行的/home/u650032727/public_html/android/Register.php中给出null [&#34; SUCCESS&#34;]&#39;

1 个答案:

答案 0 :(得分:2)

也许你的网址出错了。有一个双<ui-view/>,`https。删除一个并重试。

http