Как подключиться к базе данных mysql в android studio с помощью PHP?
Я пытаюсь подключиться к mysql на android studio с помощью php и php conect right, но проблема заключается в коде android.
Что я уже пробовал:
public class BackgroundWorker extends AsyncTask<String, Void, String> { Context context; ProgressDialog alertDialog; public BackgroundWorker(Context context){ this.context = context; } @Override protected String doInBackground(String... params) { String type = params[0]; String login_url = "http://127.0.0.0/login.php"; if(type.equals("login")){ try { String user_name = params[1]; String user_pass = params[2]; URL url = new URL(login_url); HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection(); httpURLConnection.setRequestMethod("POST"); httpURLConnection.setDoOutput(true); httpURLConnection.setDoInput(true); httpURLConnection.setUseCaches(false); OutputStream outputStream = httpURLConnection.getOutputStream(); //When it get to this line of code it jumps out to the exception BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8")); String post_data = URLEncoder.encode("user_name", "UTF-8")+"="+URLEncoder.encode(user_name, "UTF-8")+"&" +URLEncoder.encode("user_pass", "UTF-8")+"="+URLEncoder.encode(user_name, "UTF-8"); bufferedWriter.write(post_data); bufferedWriter.flush(); bufferedWriter.close(); outputStream.close(); InputStream inputStream = httpURLConnection.getInputStream(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1")); String result = ""; String line = ""; while ((line = bufferedReader.readLine()) != null) { result += line; } bufferedReader.close(); inputStream.close(); httpURLConnection.disconnect(); return result; } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { //It jups to this exception and give an error e.printStackTrace(); } } return null; }
Richard MacCutchan
Можете ли вы успешно подключиться из браузера? Кроме того, вы можете попробовать реальный IP-адрес компьютера.
David Crow
} catch (IOException e) { //It jups to this exception and give an error
И в чем именно будет заключаться эта ошибка?