Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String url = "http://xxxxxx.net:1900/login";
- URL obj = new URL(url);
- HttpURLConnection con = (HttpURLConnection) obj.openConnection();
- con.setReadTimeout(5000);
- //add reuqest header
- con.setRequestMethod("POST");
- con.setRequestProperty("User-Agent", USER_AGENT);
- con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
- String urlParameters = "username=myusername&password=mypsw";
- // Send post request
- con.setDoOutput(true);
- DataOutputStream wr = new DataOutputStream(con.getOutputStream());
- wr.writeBytes(urlParameters);
- wr.flush();
- wr.close();
- int responseCode = con.getResponseCode();
- String headerName=null;
- String cookie="";
- for (int i=1; (headerName = con.getHeaderFieldKey(i))!=null; i++) {
- if (headerName.equals("Set-Cookie")) {
- cookie = con.getHeaderField(i);
- }
- }
- //print my cookie
- System.out.println("PRIMO COOKIE "+ cookie);
- String url = "http://xxxx.net:1910/myrequest";
- URL obj = new URL(url);
- HttpURLConnection con = (HttpURLConnection) obj.openConnection();
- con.setReadTimeout(5000);
- //add reuqest header
- con.setRequestProperty("Host", "http://xxxx.net:1910");
- con.setRequestProperty("User-Agent", USER_AGENT);
- con.setRequestProperty("Accept","*/*");
- con.setRequestProperty("Accept-Language", "it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4");
- con.setRequestProperty("Cookie", c); //c is String of my cookie
- con.setRequestProperty("Connection", "keep-alive");
- int responseCode = con.getResponseCode();
- String headerName=null;
- String cookie="";
- for (int i=1; (headerName = con.getHeaderFieldKey(i))!=null; i++) {
- if (headerName.equals("Set-Cookie")) {
- cookie = con.getHeaderField(i); // <--- the cookie is empty. why?
- }
- }
- System.out.println("SECONDO COOKIE "+ cookie);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement