@Test public void test_temp(){ String url="http://ssov1.59iedu.com/login?TARGET=http://med.ihbedu.com:80/gateway/web/sso/auth&js&callback=loginThen&1470491151264&nocache=1470491171451"; this.HttpGet(url); } public void HttpGet(String url) { CloseableHttpClient httpClient = HttpClients.createDefault();//創建httpclient HttpGet httpGet = new HttpGet(url);//創建httpget System.out.println("get請求的地址:" + httpGet.getURI()); try { CloseableHttpResponse response = httpClient.execute(httpGet);//執行get請求,並結果保存 System.out.println("get請求返回的狀態碼:" + response.getStatusLine().getStatusCode()); HttpEntity httpEntity = response.getEntity();//將保存的response轉爲實體 try { if (httpEntity != null) { { System.out.println("get請求返回的response值:" + EntityUtils.toString(httpEntity)); System.out.println("lt的值:"+EntityUtils.toString(httpEntity).split("lt:\"")[1].split("\",")[0]); } } } finally { EntityUtils.consume(httpEntity);//關閉實體 response.close();//關閉response } } catch (IOException e) { e.printStackTrace(); } finally { try { httpClient.close();//關閉httpclient } catch (IOException e) { e.printStackTrace(); } } }
System.out.println("get請求返回的response值:" + EntityUtils.toString(httpEntity));
System.out.println("lt的值:"+EntityUtils.toString(httpEntity).split("lt:\"")[1].split("\",")[0]);java
String responseStr=EntityUtils.toString(httpEntity);
System.out.println("get請求返回的response值:" + responseStr);
String str=responseStr.split("lt:\"")[1].split("\",")[0];
System.out.println("lt的值:"+str);web