For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

Sunday, September 21, 2014

Get cookies in java

How to get cookies in java


import java.io.*;
import java.net.*;
public class CO {
    public static void main(String ss[]) {
     try {
             String url="http://www.mywebsite.com/anything.do";
              HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
        System.out.println("\n[HTTP GET RESPONSE]");
        System.out.println("==== Response Headers =====");
        String serverCookies = conn.getHeaderField("Set-Cookie");
        if(serverCookies != null) {
                    String[] cookies = serverCookies.split(";");
                    for(String s : cookies){
                        s = s.trim();
                        if(s.split("=")[0].equals("JSESSIONID")){
                                String J_SESSION_ID = s.split("=")[1];
                                System.out.println(" Session ID Found: " + J_SESSION_ID);
                            }
            }
        }
    } catch(Exception ee) {
        System.out.println(ee.toString());
    }
    }
}

Share:

0 comments:

Post a Comment

How to make center align child div

 How to make center align child div?   Suppose you have 2 Div tag. And want the make inner tag center <div id="d1">      ...

Ads Inside Post

Powered by Blogger.

Arsip

Blog Archive