im试图将我的Android应用程序与用于网站的数据库im连接,但不知何故它不想连接这是我的java代码im用于连接我添加的安卓清单 <uses-permission android:name="android.permission.INTERNET"></uses- permission>背景.javapackage com.example.myapplication;import android.app.AlertDialog;import android.content.Context;import android.os.AsyncTask;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.OutputStream;import java.io.OutputStreamWriter;import java.net.HttpURLConnection;import java.net.MalformedURLException;import java.net.URL;import java.net.URLEncoder;public class backgroundworker extends AsyncTask<String,Void, String> {Context context;AlertDialog alertDialog;backgroundworker(Context ctx){ context =ctx;}@Overrideprotected String doInBackground(String... params) { String type = params[0]; String login_url = "http://10.0.2.2//android/login.php"; if (type.equals("login")){ try { String Email = params[1]; String Password = params[2]; URL url = new URL(login_url); HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection(); httpURLConnection.setRequestMethod("POST"); httpURLConnection.setDoOutput(true); httpURLConnection.setDoInput(true); OutputStream outputStream = httpURLConnection.getOutputStream(); BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
1 回答
潇潇雨雨
TA贡献1833条经验 获得超4个赞
此行
if ($Email == $row ['Email'] and $Password == $dbPassword) {
是错误的/问题。您已经password_verified,这会返回一个boolan,因此它应该如此。
if ($Email == $row ['Email'] and $Password) {
而且您不需要重新检查$Email == $row ['Email'],因为您已经查询过它。
因此,您可以将代码简化为:
if (mysqli_num_rows($res)>0) {
$dbPassword = $row['Password'];
if (PASSWORD_VERIFY($Password, $dbPassword)) {
$id = $row['id'];
$_SESSION['id'] = $id;
exit();
} else {
//...
添加回答
举报
0/150
提交
取消