php ->


<?

if($_GET["id"] == "1234567" && $_GET["pwd"] = "1111"){

echo "\nwelcome ingbeeni<br />\n";

echo "date:".date("Y-m-d")."\n";

echo "id:". $_GET["id"]. "\n";

echo "password:" . $_GET["pwd"]." \n";

echo "file path:".$_SERVER["PHP_SELF"]." \n";

echo "login ip:".$_SERVER["REMOTE_ADDR"]."\n";

} else {

echo " id or password is not matched.[홍길동]\n";

echo "id:".$_GET["id"]." \n";

echo "pw:".$_GET["pwd"]." \n";

}

?>

chrome -> http://127.0.0.1/test.php?id=1234567&pwd=1111


오류 android.os.NetworkOnMainThreadException

-> 안드로이드 버전업으로 인한 예외발생

-> Main thread(UI) 에서 네트워크 호출을 무조건 error로 간주

-> 네트워크 작업을 UI스레드가 아닌 별도의 스레드에서 처리해야함


해결방안

-> AndroidManifest.xml파일에서 <uses-sdk >를 지우거나 주석처리

-> StrictMode ThreadPolicy를 수정

-> 못적음 하나더있음



Manifest

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.example.s08"

    android:versionCode="1"

    android:versionName="1.0" >


    <uses-sdk

        android:minSdkVersion="8"/>

        <!--android:targetSdkVersion="18"--> 

      

<uses-permission android:name="android.permission.INTERNET"/>

    <application

        android:allowBackup="true"

        android:icon="@drawable/ic_launcher"

        android:label="@string/app_name"

        android:theme="@style/AppTheme" >

        <activity

            android:name="com.example.s08.MainActivity"

            android:label="@string/app_name" >

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />


                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

    </application>


</manifest>


MainActiviy.java

package com.example.s08;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends Activity {
TextView tv_message;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv_message = (TextView)findViewById(R.id.tv_message);
URL url = null;
HttpURLConnection urlconnection = null;
BufferedReader rbuf = null;
String str = "";
try {
url = new URL("http://***.**.***.***/test.php?id=1234567&pwd=1111");
urlconnection = (HttpURLConnection)url.openConnection();
if(urlconnection.getResponseCode() == HttpURLConnection.HTTP_OK){
rbuf = new BufferedReader(new InputStreamReader(urlconnection.getInputStream(), "UTF-8"));
while ((str = rbuf.readLine()) != null){
tv_message.append(str+"\n");
}
}
urlconnection.disconnect();
} catch (Exception e) {
Log.i("web","오류 :" + e);
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}





'이전것 > 개발' 카테고리의 다른 글

android -> Server -> xml  (0) 2016.07.08
android -> Server -> android  (0) 2016.07.08
android -> webView  (0) 2016.07.07
android -> LifeCycle  (0) 2016.07.07
android -> binary search game  (0) 2016.07.07
블로그 이미지

잉비니

,