阅读背景:

httpclient 访问https应用

来源:互联网 

HTTPS

public class Test 
{
		 public static HttpClient wrapClient(HttpClient base) throws Exception
		 {  
	         SSLContext ctx = SSLContext.getInstance("TLSv1");  
	         X509TrustManager tm = new X509TrustManager(){  
	         public X509Certificate[] getAcceptedIssuers()  
	         {  
	           return null;  
	         }  
	         public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException  {}  
	         public void checkServerTrusted(X509Certificate[] arg0, String arg1)throws CertificateException{}  
	         };  
	 
	         ctx.init(null, new TrustManager[] { tm }, null);  
	         SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);  
	         ClientConnectionManager ccm = base.getConnectionManager();  
	         SchemeRegistry registry = ccm.getSchemeRegistry();  
	         registry.register(new Scheme("https", 443, ssf));  
	         return new DefaultHttpClient(ccm, base.getParams());  
	   }  
	 
	 public static void main(String args[]) throws Exception 
	 {  
	        HttpClient client=wrapClient(new DefaultHttpClient());  
//	        HttpGet get=new HttpGet("https://beta.openimslive.com/omp/oauth/authorize?app_key=cqMIkoEd9AUrktTP7EMWNykTwlka&response_type=code&redirect_uri=https://www.engyne.net");
//	        get.setHeader("Host", "1.1.1.1:8543");
//	        get.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
//	        get.setHeader("Accept", "text/html, application/xhtml+xml, */*");
	        String fastloginUsername = "+8675566552003";
	        String fastloginPassword = "mdx3600@HW";
	        String server = "205.177.226.80:8543";
	        String appKey = "wfbVlIqjuT4miYMFxmqhMSn2Bsoa";
	        OmpRestClient Restclient = new OmpRestClient(server, appKey);
	        String accessToken=Restclient.getFastloginToken(fastloginUsername, fastloginPassword);
	        System.out.println(accessToken);
	        String url="https://193.3.2.16:8543/sandbox/rest/httpsessions/click2Call/v1.0?app_key=nGe8HpnhunNsh5yYGT8xfcAE9dsa&access_token="+"+accessToken+"+"&format=json";
	        HttpPost post = new HttpPost(url);
			//post.setHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8"); 
			 List<BasicNameValuePair> formparams = new ArrayList<BasicNameValuePair>();
			 formparams.add(new BasicNameValuePair("calleeNbr","+8613163359533"));  
		     formparams.add(new BasicNameValuePair("callerNbr","+867556666663036"));  
		     formparams.add( new BasicNameValuePair("displayNbr","+867556666663036"));  
		     formparams.add(new BasicNameValuePair("languageType","1"));  
			 UrlEncodedFormEntity uefEntity= new UrlEncodedFormEntity(formparams, "UTF-8");  
			 post.setEntity(uefEntity); 
	        
	        HttpResponse resp=client.execute(post);  
	        System.out.println(resp.toString());
	        System.out.println(resp.getStatusLine().getStatusCode());  
	        System.out.println(resp.getEntity().getContent());
	  }  
}public class Test 
{
		 public stati



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: