protected String doInBackground(String... params) {
try {
// Enter URL address where your php file resides
url = new URL("http://192.168.43.230:25689/test/login.php");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "exception";
}
try {
// Setup HttpURLConnection class to send and receive data from php and mysql
conn = (HttpURLConnection)url.openConnection();
conn.setRequestProperty("User-Agent", "Mozilla/5.0");
conn.setReadTimeout(READ_TIMEOUT);
conn.setConnectTimeout(CONNECTION_TIMEOUT);
conn.setRequestMethod("POST");
// setDoInput and setDoOutput method depict handling of both send and receive
conn.setDoInput(true);
conn.setDoOutput(true);
// Append parameters to URL
Uri.Builder builder = new Uri.Builder()
.appendQueryParameter("username", params[0])
.appendQueryParameter("password", params[1]);
String query = builder.build().getEncodedQuery();
// Open connection for sending data
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os, "UTF-8"));
writer.write(query);
writer.flush();
writer.close();
os.close();
conn.connect();
} catch (IOException e1) {
// TODO Auto-generated catch block
return e1.getMessage();
//return "exception";
}
try {
int response_code = conn.getResponseCode();
// Check if successful connection made
if (response_code == HttpURLConnection.HTTP_OK) {
// Read data sent from server
InputStream input = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
StringBuilder result = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
result.append(line);
}
// Pass data to onPostExecute method
return(result.toString());
}else{
return Integer.toString(response_code);
//return("unsuccessful");
}
PHP 스크립트 (wamp 서버)를 실행하려고합니다. 내 모바일에 내 안드로이드 응용 프로그램. 모바일과 내 컴퓨터를 동일한 네트워크에 연결했습니다.안드로이드 응용 프로그램을 통해 내 localhost에서 PHP 스크립트에 액세스하는 중 예기치 않은 연결이 {192.168.43.230:25689, ..}에 연결됩니다.
응답 코드는 403.I가 방화벽을 비활성화하고 사용자 에이전트도 추가 함을 보여줍니다.
누구든지 오류의 가능성을 알 수 있습니까?
PHP 코드를 몇 가지 간단한 정적 HTML로 대체하면 어떻게됩니까? 안드로이드 브라우저에서 URL을 열려고하면 어떻게됩니까? – NineBerry
PHP를 html 파일로 바꾸더라도 오류는 여전히 동일합니다. @ NineBerry – Jab
Android의 브라우저 앱에서 URL을 열려고하면 어떻게됩니까? – NineBerry