java模擬網頁http-url訪問
阿新 • • 發佈:2017-12-12
system service blog () uil let ada sso builder
package com.iflytek; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; public class ssodemo { public static void main(String[] args) throws Exception { //cas server 校驗地址 String serverValidateUrl="https://demo.tch.com:8443/cas/serviceValidate";//客戶端地址 String service = "http://app1.tch.com:18080/examples/servlets/servlet/HelloWorldExample"; //ticket String ticket ="ST-7-gCMvfsyy9hmnadayB1e3-cas01.example.org"; //組裝url String constructServiceUrl = serverValidateUrl+"?ticket="+ticket+"&service="+service; System.out.println("constructServiceUrl:"+constructServiceUrl); URL url =new URL(constructServiceUrl); HttpURLConnection conn = (HttpURLConnection)url.openConnection(); conn.setConnectTimeout(5*1000); conn.setRequestMethod("GET"); InputStream inStream = conn.getInputStream();final StringBuilder builder = new StringBuilder(255); int byteRead; while ((byteRead = inStream.read()) != -1) { builder.append((char) byteRead); } String response = builder.toString(); System.out.print("response:"+response); } }
java模擬網頁http-url訪問