HttpURLConnection send cookies not working


J

JonS

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 "--><--".


?>
 
Ad

Advertisements


Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top