XilongPei / Openparts

MIT License
3 stars 1 forks source link

实现callMyService功能 #69

Open XilongPei opened 6 years ago

XilongPei commented 6 years ago

每个人都对应一个Org,而有些功能,是由Org提供的,所有的Org提供的接口是一致的,但服务地址URL不同。当这个用户请求这类功能时,需要间接调用Org的实际服务提供者来完成。

XilongPei commented 6 years ago

HTTPClient和URLConnection核心区别分析 https://blog.csdn.net/lixiaopeng23/article/details/9799197

XilongPei commented 6 years ago

HttpClient详细实例,Httoclient调用https实例,避免https SSL认证 https://blog.csdn.net/dcb_ripple/article/details/51012648

public static void testHttpClient2(){

    HttpClient httpclient = new DefaultHttpClient();  

    String url ="http://xxxxx:xxxxx/tnserver/property_manager/login";  
    try {  

        HttpPost httppost = new HttpPost(url);  

        //==========http认证过程===================== 如无需采用https协议进行调用,可忽略https认证过程  
        //注:此方法只用于import org.apache.http.client.HttpClient; 新版本的认证  

        //旧版本:import org.apache.commons.httpclient 认证方法如下:  
        //Credentials defaultcreds = new UsernamePasswordCredentials("userxxx","pwdxxx");  
        //httpClient.getState().setCredentials(AuthScope.ANY, defaultcreds);  
        //注意。 旧版本的认证方式导入的包是 带 org.apache.commons.xxxx  

        //创建https认证对象    
        CredentialsProvider credsProvider = new BasicCredentialsProvider();  
        //写入认证的用户名与密码  
        UsernamePasswordCredentials creds = new UsernamePasswordCredentials("xxx", "xxx");   
        //创建验证    
         credsProvider.setCredentials(    
             new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),     
             creds);  
         //将认证写入到httpClient中    
         ((DefaultHttpClient)httpclient).setCredentialsProvider(credsProvider);     
         //=========Https认证===end=============================  

        httppost.addHeader("Content-type", "application/x-www-form-urlencoded");   

        JSONObject json = new JSONObject();  
        json.put("username", "xxxx");  
        json.put("password", "xxxxx");  
        StringEntity entity = new StringEntity(json.toString());  

        httppost.setEntity(entity);  

        HttpResponse post= httpclient.execute(httppost);  

        if (post.getStatusLine().getStatusCode() == 200) {    

            String conResult =  EntityUtils.toString(post.getEntity());  

            JSONObject sobj = new JSONObject();    
            sobj = JSONObject.fromObject(conResult);  
            System.out.println(sobj);  
        } else {    
           System.out.println("失败....");  
        }  
    }catch(Exception e){  
        e.printStackTrace();  
    }finally{  

    }  
}  
XilongPei commented 6 years ago

基于HttpClient 4.3的可访问自签名HTTPS站点的新版工具类 https://blog.csdn.net/chaijunkun/article/details/40145685

HttpClient(4.3.5)请求数据,支持https http://m635674608.iteye.com/blog/2340079

XilongPei commented 6 years ago

enhance HttpUtils, support https protocol commit: https://github.com/XilongPei/Openparts/commit/7865f0aa343ecfedcaed9a6cbe81dbbd46e26590

XilongPei commented 6 years ago

Http请求连接池 - HttpClient 的 PoolingHttpClientConnectionManager https://blog.csdn.net/catoop/article/details/50352334