I used HttpClient AS THE post request today and reported an error.
First error: HttpHostConnectException: Connection to http://192.168.xx.xx refused
You just need to change the IP address to http: // 10.0.2.2 ~ This is the network segment of the simulator.
Or 127.0.0.1 or localhost, which indicates the virtual machine itself.
---- Add the following content to the configuration file manifest. xml:
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" ></uses-permission> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" ></uses-permission> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" ></uses-permission> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" ></uses-permission> <uses-permission android:name="android.permission.INTERNET" ></uses-permission> <uses-permission android:name="android.permission.WAKE_LOCK" ></uses-permission>
Permission. WIFI or something can be deleted
Another error:
Project is 2.2 development and testing mobile phone is android4.0 prompt android. OS. networkOnMainThreadException exception. Originally in 4.0, the access network cannot be performed in the main program. There are two solutions, one being added to the main program:
New Thread () {@ Override public void run () {// method to be executed // send an empty message to handler after execution. sendEmptyMessage (0 );}}. start (); // define the Handler object private Handler handler = new Handler () {@ Override // when a Message is sent, execute the Handler public void handleMessage (Message msg) {super. handleMessage (msg); // process the UI }};
If the request is written in the main process, it does not comply with android specifications. It will also cause the user interface to die.
This article is from the "FlyHome" blog, please be sure to keep this source http://superfly81.blog.51cto.com/6302302/1279036