Created
June 11, 2016 16:28
-
-
Save FloydHsiu/a9d55eb5d012ec64b4d1442680c90712 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static public void getCookie() throws IOException | |
{ | |
HttpURLConnection HttpConn; | |
URL Url = new URL(INDEX_URL); | |
HttpConn = (HttpURLConnection) Url.openConnection(); | |
System.out.println(HttpConn); | |
HttpConn.setConnectTimeout(15000); | |
HttpConn.setReadTimeout(10000); | |
HttpConn.setRequestMethod("GET"); | |
HttpConn.setDoInput(true); | |
HttpConn.setDoOutput(false); | |
//start the query | |
HttpConn.connect(); | |
int response = HttpConn.getResponseCode();//http 200,403 ...... | |
if(response == 200) | |
{ | |
String Session_header = HttpConn.getHeaderField("Set-Cookie"); | |
if(Session_header != null) | |
{ | |
cookieManager.getCookieStore().add(null, HttpCookie.parse(Session_header).get(0)); | |
} | |
} | |
else | |
{ | |
System.out.println("GG"); | |
throw new IOException(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment