Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- baseURL = // a https URL;
- urlMap = new HashMap<String, URL>();
- urlMap.put("login", new URL(baseURL, "exec.asp?login=username&pass=XPTO"));
- urlMap.put("logout", new URL(baseURL, "exec.asp?exec.asp?page=999"));
- urlMap.put("file", new URL(baseURL, "exec.asp?file=111"));
- urlConnection = urlMap.get("login").openConnection();
- urlConnection.connect();
- BufferedReader in = new BufferedReader(
- new InputStreamReader(urlConnection.getInputStream()));
- String inputLine;
- while ((inputLine = in.readLine()) != null)
- System.out.println(inputLine);
- in.close();
- class MyCookieHandler extends CookieHandler {
- private Map<String, List<String>> cookies = new HashMap<String, List<String>>();
- @Override
- public Map<String, List<String>> get(URI uri,
- Map<String, List<String>> requestHeaders) throws IOException {
- String host = uri.getHost();
- Map<String, List<String>> ret = new HashMap<String, List<String>>();
- synchronized (cookies) {
- List<String> store = cookies.get(host);
- if (store != null) {
- store = Collections.unmodifiableList(store);
- ret.put("Cookie", store);
- }
- }
- return Collections.unmodifiableMap(ret);
- }
- @Override
- public void put(URI uri, Map<String, List<String>> responseHeaders)
- throws IOException {
- List<String> newCookies = responseHeaders.get("Set-Cookie");
- if (newCookies != null) {
- String host = uri.getHost();
- synchronized (cookies) {
- List<String> store = cookies.get(host);
- if (store == null) {
- store = new ArrayList<String>();
- cookies.put(host, store);
- }
- store.addAll(newCookies);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment