HttpURLConnection send cookies not working

Discussion in 'Java' started by JonS, Aug 21, 2006.

  1. JonS

    JonS Guest

    Hi,
    I'm using this code (below) to send a cookie to a server. The PHP page
    connected to is supposed to echo out the cookie value "color". I've
    inspected the traffic between my client and the server and NO cookie
    information is sent. In fact no other custom header information is sent
    to the server?!

    The server successfully sends cookies to my client, but I cannot return
    them.

    I read that there was a bug in JRE before build 1.5.0_08-b03 that
    caused, this.
    I have upgraded to (build 1.5.0_08-b03), but the bug persists.

    I've searched everywhere, and all the articles I have found seem to not
    hit this problem?
    - so what am I doing wrong I wonder?
    Has anyone got a minimal java app that does send cookies successfully?
    - do you mind sahring it?



    URL url = new URL(strURL.toString());
    HttpURLConnection conn = (HttpURLConnection)
    url.openConnection();
    conn.setRequestProperty("Cookie", "color=red;");
    conn.connect();
    // Read all the text returned by the server
    BufferedReader in = new BufferedReader(new
    InputStreamReader(url.openStream()));
    System.out.println(in.readLine()); // this prints "--><--"
    (see php page below)
    in.close();
    in=null;
    conn=null;
    url=null;


    <?php

    echo "-->$_COOKIE[color]<--"
    // should echo "-->red<--", but only echos "--><--".


    ?>
    JonS, Aug 21, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Martin Heuckeroth
    Replies:
    5
    Views:
    666
    JiangZemin
    Apr 1, 2005
  2. Flip
    Replies:
    8
    Views:
    661
  3. Siegfried Ertl

    HttpURLConnection

    Siegfried Ertl, Nov 30, 2003, in forum: Java
    Replies:
    1
    Views:
    2,238
    Sudsy
    Nov 30, 2003
  4. Syed Ali
    Replies:
    1
    Views:
    823
    kpl_pl
    Jul 20, 2007
  5. _Who
    Replies:
    7
    Views:
    2,625
Loading...

Share This Page