Package com. http. test;
Import org. apache. http. HttpResponse;
Import org. apache. http. HttpStatus;
Import org. apache. http. client. HttpClient;
Import org. apache. http. client. methods. HttpGet;
Import org. apache. http. impl. client. DefaultHttpClient;
Import org. apache. http. util. EntityUtils;
Import org. json. JSONException;
Import org. json. JSONObject;
Import org. json. JSONTokener;
Import android. app. Activity;
Import android. OS. Bundle;
Import android. view. View;
Import android. view. View. OnClickListener;
Import android. widget. Button;
// Import android. widget. EditText;
Import android. widget. TextView;
Public class Http_testActivity extends Activity {
/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
Final TextView TV = (TextView) findViewById (R. id. result );
// Final EditText ed = (EditText) findViewById (R. id. sendurl );
Button bt = (Button) findViewById (R. id. send );
Bt. setOnClickListener (new OnClickListener () {// create the first click event
Public void onClick (View v ){
String strResult = null;
Try {
String httpUrl = "http: // 10.10.10.10: 61002/userMessage/cJobConsultationUnread. json? Data = 688656 & client_id = 20012 & view_id = 268800 ";
// HttpGet connection object
HttpGet httpRequest = new HttpGet (httpUrl );
// Get the HttpClient object
HttpClient httpclient = new DefaultHttpClient ();
// Request HttpClient to obtain HttpResponse
HttpResponse httpResponse = httpclient.exe cute (httpRequest );
// The request is successful.
If (httpResponse. getStatusLine (). getStatusCode () = HttpStatus. SC _ OK ){
// Obtain the returned string
StrResult = EntityUtils. toString (httpResponse
. GetEntity ());
TV. setText (strResult );
} Else {
TV. setText ("request error! ");
}
} Catch (Exception e ){
}
// Returned json string strResult = {"status": 0, "message": "OK", "data": 15}
Try {
JSONTokener jsonParser = new JSONTokener (strResult );
JSONObject js = (JSONObject) jsonParser. nextValue ();
// The next step is the JSON object operation.
System. out. println ("status value:" + js. getString ("status "));
System. out. println ("message Value:" + js. getString ("message "));
System. out. println ("data value:" + js. getInt ("data "));
} Catch (JSONException ex ){
// Exception Handling Code
}
}
});
}
}
From mobile Internet performance, android automation, and web automation testing Column