HttpClient access network, httpclient access
In the HttpClient project, Apache provides classes for accessing the network and encapsulates the methods for accessing the network. The input and output operations in the HttpURlConnection class are encapsulated into HttpGet, HttpPost, and HttpResponse
I. Server front-end
1. Steps for sending a GET request:
(1) Create an HttpClient object: HttpClient httpClient = new DefaultHttpClient ();
(2) create HttpGet object: HttpGet httpGet = new HttpGet (http://www.baidu.com );
(3) Add the sending parameter httpGet. setParams ("the girl's eyes are really big, so pretty! ");
(4) Call the execute () method of the HttpClient object to send the request:
HttpResponse httpResponse=httpClient.exe cute ();
Example:
HttpClient httpClient = new DefaultHttpClient ();
HttpGet httpGet = new HttpGet (http://www.iciba.com );
HttpGet. setParams ("awesome! ");
Tyr {
HttpResponse httpResponse=httpClient.exe cute ();
// Determine whether the server responds
If (httpResponse. getStatusLine (). getStatusCode () = HttpStatus. SC _ OK ){
Result = EntityUtils. toString (httpResponse. getEntiry (); // obtain the returned string
} Else {result = "request failed! ";}
} Catch (ClientProtocolException e ){
E. printStackTrace ();
} Catch (IOException e) {e. printStackTrace ();};
Android uses HttpClient to access the network server and the client.
Answer: The preliminary judgment is that there is a problem with json parsing. In general, you must specify the content of the json string to parse json. In layman's terms, you need to know the structure of the entire json string. There are several braces {}, including nested braces {} and several braces [], including nested []. Then, the outer and inner layers must be braces {}, which is a json object, that is, JsonObject. Then, at this layer, check whether there are any brackets []. the json array is JsonArray. The Field Values of the current layer can be obtained based on the json object and field names of the current layer. In this case, move down a layer of json object, that is, view the second braces {}, and so on.
I am a beginner. After I log on to httpClient, I want to access the specified webpage. What should I do? Teach me,
Official webpage examples and quickstart
Https: Colon // hc: apache: org/httpcomponents-client-ga/index.html
Replace the Chinese characters