小编sha*_*een的帖子

Android中的Http Get和Post方法异常?

我正在使用Http get和post方法进行Http连接我只是想问一下使用它们会发生什么异常.我知道列表可能太长了但是有人可以告诉我发生的一般和频繁的异常并且必须处理吗?我的代码是:

public class httpconnection
    {

    HttpClient client=new DefaultHttpClient();
      InputStream in=null;


    public InputStream httpreponse_post(String url,List<NameValuePair> params)
     {
      try {

    HttpPost post = new HttpPost(url); 
        UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params,HTTP.UTF_8);
        post.setEntity(ent);
        HttpResponse responsePOST = client.execute(post);  
        HttpEntity resEntity = responsePOST.getEntity();  
        in=resEntity.getContent();
        in.close();

} catch (ClientProtocolException e)
 {
 Log. e ("Client Protocol Exception", e.toString ());
 }
 catch (IOException e) {
 Log. e ("Input Output Exception", e.toString ());
  }
  return in;
    }



 public InputStream httpreponse_get(String url)
  {
     try 
    {


  //String getURL = "http://www.google.com";
 HttpGet …
Run Code Online (Sandbox Code Playgroud)

android http

1
推荐指数
1
解决办法
2936
查看次数

标签 统计

android ×1

http ×1