java 如何在android studio中修复网络安全配置?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40352998/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to fix network security config in android studio?
提问by Jun Jie
i am trying to insert data to a webhost , after i click on the ,my app it will insert data into the database and then go back to login page. but when i click on the register button my app does not back to the login page , the data does not insert and at the logcat it show networksecurityconfig. How do i fix this problem?
我正在尝试将数据插入虚拟主机,在我点击后,我的应用程序会将数据插入数据库,然后返回登录页面。但是当我点击注册按钮时,我的应用程序没有返回登录页面,数据没有插入,并且在 logcat 中显示networksecurityconfig。我该如何解决这个问题?
RegisterRequest.java:
注册请求.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:
注册Activity.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:
<?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);
?>
Locat:
地点:
'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'
in my (http://finalproject.16mb.com/android/Register.php),itcome out this error:
在我的(http://finalproject.16mb.com/android/Register.php)中,出现了这个错误:
'Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/u650032727/public_html/android/Register.php on line 2
'已弃用:mysql_connect():mysql 扩展已弃用,将来会被删除:在第 2 行的 /home/u650032727/public_html/android/Register.php 中使用 mysqli 或 PDO 代替
Warning: mysqli_prepare() expects parameter 1 to be mysqli, resource given in /home/u650032727/public_html/android/Register.php on line 9
警告:mysqli_prepare() 期望参数 1 为 mysqli,第 9 行 /home/u650032727/public_html/android/Register.php 中给出的资源
Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, null given in /home/u650032727/public_html/android/Register.php on line 10
警告:mysqli_stmt_bind_param() 期望参数 1 为 mysqli_stmt,第 10 行 /home/u650032727/public_html/android/Register.php 中给出的 null
Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, null given in /home/u650032727/public_html/android/Register.php on line 11 ["SUCCESS"]'
警告:mysqli_stmt_execute() 期望参数 1 为 mysqli_stmt,在第 11 行的 /home/u650032727/public_html/android/Register.php ["SUCCESS"]' 中给出空值
回答by mrKIP
Maybe you have made a mistake in your url. There is a double http
, `https. Remove one and try again.
也许您的网址有误。有一个双http
,`https。删除一个并重试。
private static final String REGISTER_REQUEST_URL = "http://finalproject.16mb.com/public_html/android/Register.php";