• Httpclient请求数据


    package com.baidu.myutils;
    
    import java.io.IOException;
    
    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.ClientProtocolException;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.params.BasicHttpParams;
    import org.apache.http.params.HttpConnectionParams;
    import org.apache.http.params.HttpParams;
    import org.apache.http.util.EntityUtils;
    
    public class MyUtils {
        
        String url="http://apis.juhe.cn/goodbook/catalog?key=9d6ef8c31647a206e05fcaff70527182&dtype=json";
    
        
        public static String Check_j(String url){
            String str="";
            HttpGet get=new HttpGet(url);
            HttpParams params=new BasicHttpParams();
            HttpConnectionParams.setConnectionTimeout(params, 5000);
            HttpConnectionParams.setSoTimeout(params, 5000);
            HttpClient client=new DefaultHttpClient(params);
            try {
                HttpResponse response=client.execute(get);
                
                
                if(response.getStatusLine().getStatusCode()==200){
                    HttpEntity entity=response.getEntity();
                    str=EntityUtils.toString(entity, "utf-8");
                    
                }
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return str;
        }
    }
  • 相关阅读:
    Repeater添加删除按钮
    C# Excel导出后台代码
    MOSS层级结构Excel导入SPList
    Excel导入到datatable
    层级结构SPList导出到Excel
    SPlist按PID层级顺序导入datatable
    .NET导出Excel遇到的80070005错误的解决方法:
    datatable转到Excel
    MOSS获取SPListItem某版本
    sharepoint实现假分页
  • 原文地址:https://www.cnblogs.com/1995yu/p/5452689.html
Copyright © 2020-2023  润新知