PHP code ===============================$ array = array (& amp; #39; username & amp; #39 ;=& gt; & amp; #39; Yang Zhu & amp; #39 ;,& amp; #39; password & amp; #39; = & gt; & amp; #39; 123456 & amp; #39 ;,&
PHP code =============================$ array = array ('username' => 'yangzhu ', 'password' => '000000', 'User _ id' => 1 );
Echo json_encode ($ array );
Java code =
Private void startUrlCheck (String username, String password) {HttpClient client = new DefaultHttpClient (); StringBuilder builder = new StringBuilder (); HttpGet myget = new HttpGet (" http://10.0.2.2 /Android/index. php "); try {HttpResponse response = client.exe cute (myget); BufferedReader reader = new BufferedReader (new InputStreamReader (response. getEntity (). getContent (); for (String s = reader. readLine (); s! = Null; s = reader. readLine () {builder. append (s);} JSONObject jsonObject = new JSONObject (builder. toString (); String re_username = jsonObject. getString ("username"); String re_password = jsonObject. getString ("password"); int re_user_id = jsonObject. getInt ("user_id"); setTitle ("User ID _" + re_user_id); Log. v ("url response", "true =" + re_username); Log. v ("url response", "true =" + re_password);} catch (Exception e) {Log. v ("url response", "false"); e. printStackTrace ();}} running result = http://10.0.2.2 The IP address used by Android to access the local url. Corresponding to the test on the computer http://127.0.0.1 In addition, an exception PHP100.com java.net. SocketException: Permission denied is thrown during code execution. This means that the application has insufficient network access permissions in AndroidManifest. xml and requires the following configuration: AddIt was done before and the test passed.