新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > Android网络编程之Http通信

Android网络编程之Http通信

作者: 时间:2016-09-12 来源:网络 收藏

//请求httpRequest

httpRequest.setEntity(httpentity);

//取得默认的HttpClient

HttpClient httpclient = new DefaultHttpClient();

//取得HttpResponse

HttpResponse httpResponse = httpclient.execute(httpRequest);

//HttpStatus.SC_OK表示连接成功

if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK)

{

//取得返回的字符串

String strResult = EntityUtils.toString(httpResponse.getEntity());

mTextView.setText(strResult);

}

else

{

mTextView.setText(请求错误!);

}

}

HttpClient实际上是对Java提供方法的一些封装,在HttpURLConnection中的输入输出流操作,在这个接口中被统一封装成了HttpPost(HttpGet)和HttpResponse,这样,就减少了操作的繁琐性。

另外,在使用POST方式进行传输时,需要进行字符编码。


上一页 1 2 下一页

关键词:

评论


相关推荐

技术专区

关闭