Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8341637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:32:34+00:00 2026-06-09T05:32:34+00:00

Basically i just want to get cookies from server. Here’s simple code, but i

  • 0

Basically i just want to get cookies from server. Here’s simple code, but i guess it’s not enough to get every cookie like e.g sessionID etc.

import java.net.*;
import java.util.*;

    public class Cookie {

    public static void main(String[] args) {

        try {
            URL url = new URL("http://www.google.com/");
            URLConnection conn = url.openConnection();
            System.out.println(con.getHeaderField("Set-Cookie"));

        } catch (Exception e) { }
    }
}

Result shows that i get only one cookie:

NID=61=nNSsAl4g7DfxqHE7t__ghfoCc_J-RmY7PaTNoPOd_khLdvvuqI-fnteHgnQXMzmxj_C5HdMozcGfOTt8PvePLKpbDdUlzdVZiRKwNpQIej6_T69jt9C7Oi6E4F-gWPHD; expires=Mon, 14-Jan-2013 17:16:40 GMT; path=/; domain=.google.pl; HttpOnly

Firefox gets NID and PREF, so it’s not working.

Is there any way to get PREF cookie?

Can anyone tell me is this proper way(code below) to send POST.

import java.io.*;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.net.ssl.HttpsURLConnection;

public class Cookie_Example {

    public static void main(String[] args){

        try{
            String https_url = "https://ssl.filmweb.pl/j_login";
            URL url = new URL(https_url);
            String post = "_login_redirect_url=http%253A%252F%252Fwww.filmweb.pl%252F&j_username=test.filmweb%40gmail.com&j_password=test.filmweb&_rememberMe=on&pass=zaloguj";

            HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
            con.setInstanceFollowRedirects(false);
            con.setDoInput(true);
            con.setDoOutput(true);
            con.setRequestMethod("GET");
            con.setRequestProperty("Host", "ssl.filmweb.pl");
            con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0.1");
            con.setRequestProperty("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
            con.setRequestProperty("Accept-Language","pl,en-us;q=0.7,en;q=0.3");
            con.setRequestProperty("Accept-Encoding","gzip, deflate");
            con.setRequestProperty("Connection","keep-alive");
            con.setRequestProperty("Referer","https://ssl.filmweb.pl/login");
            con.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
            con.setRequestProperty("Content-Length",post.length()+"");
            DataOutput output = new DataOutputStream(new BufferedOutputStream(con.getOutputStream()));
            output.write(post.getBytes());

            Map<String, List<String>> hf = con.getHeaderFields();

            Iterator it = hf.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry pairs = (Map.Entry)it.next();
                System.out.println(pairs.getKey() + " = " + pairs.getValue());
            }
        } catch (Exception e) {
        }
    }
}

Result is empty cookie,

Set-Cookie = [_artuser_rememberMe=;Path=/;Domain=filmweb.pl;Expires=Thu, 01-Jan-1970 00:00:00 GMT]

http://img72.imageshack.us/img72/1134/testgof.jpg

Screen from Tamper Data

It means this code also doesn’t work. How Can I get __utma, __utmz etc. cookie?
Can anyone help me? Which books will be helpful?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T05:32:35+00:00Added an answer on June 9, 2026 at 5:32 am

    I think that with your statement, con.getHeaderField("Set-Cookie")" you only retrieve one header. But maybe the server sends you two cookies, in two different headers.

    I use another statement for retrieve all headers of cookies:

    List<String> cookies = connection.getHeaderFields().get("Set-Cookie");
    

    To see what you send to server, and what the server sends to you, I recommend use a proxy between your program (or web navigator) and the server. Maybe Charles proxy can help you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I just want to tar all the files in a directory, but not
I just want to design this very simple website. Basically there are multiple pages
Basically, I just want to be able to get the parameter community_name, can this
basically i just want to get all the text after the _ . i
Nothing too complicated, basically I just want to pick an element from the array
Basically I just want to put new.gif in the top left corner of the
Basically i just want to do an arbitrary operation using given arguments of arbitrary
Basically I just want to check if one time period overlaps with another. Null
I just basically want to add about 20 and sometimes 80 Proximity Alerts with
So, I just basically want to use AVFoundation Kit for playing my sound. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.