List params = new LinkedList();

params.add(new BasicNameValuePair("ajax", "1"));

String param = URLEncodedUtils.format(params, "UTF-8");

String baseUrl = "http://www.xxx.com";

Log.v("url", baseUrl+"?"+param);

HttpGet httpGet = new HttpGet(baseUrl+"?"+param);

CloseableHttpClient httpClient = HttpClients.createDefault();

try {

CloseableHttpResponse response = httpClient.execute(httpGet);

HttpEntity httpEntity = response.getEntity();

TextView codeValueTV =(TextView) findViewById(R.id.codeValue);

codeValueTV.setText(response.getStatusLine()+"");

TextView contentTV =(TextView) findViewById(R.id.content);

contentTV.setText(EntityUtils.toString(httpEntity));

} catch (IOException e) {

e.printStackTrace();

} finally {

try {

httpClient.close();

} catch (IOException e) {

e.printStackTrace();

}

}

上面是代码详情。

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐