Craig,
Thanks for the tips,
I would like to point out TWO things;
ONE: in my case the zero th header key is always seem to be null, although there is
data on the 0th header...
here's some output:
URLResponse: content encoding null
URLResponse: content length -1
URLResponse: content type text/html
URLResponse: header field key 0: null
value: HTTP/1.1 200 OK
URLResponse: header field key 1: Date
value: Wed, 25 Aug 1999 19:16:59 GMT
URLResponse: header field key 2: Server
value: IBM_HTTP_Server/1.3.3 Apache/1.3.4-dev (Unix)
URLResponse: header field key 3: Set-Cookie
value: sesessionid=00PQZHAAAAAA5FEEYJRAAAA;Path=/
URLResponse: header field key 4: Cache-Control
value: no-cache="set-cookie,set-cookie2"
URLResponse: header field key 5: Expires
value: Thu, 01 Dec 1994 16:00:00 GMT
URLResponse: header field key 6: Connection
value: close
URLResponse: header field key 7: Content-Type
value: text/html
URLResponse: header field key 8: null
value: null
URLResponse: header field key 9: null
value: null
More Importantly
TWO: Now, I can grab the cookies from the URL that is setting them. But I also need
to do the other way round, My servlet needs to send the cookies back.
how can I send the cookie (both in GET/POST methods)
back to the originating server?
I mean the URLConnection or HttpURLConnection classes
do not seem to have
setURLHeader("Cookie", "$Version=1;session_id=1234;$Path=/")
type of a method. (Although it has the getHeaderField methods)
Do I have to write it to the outstream of the URLConnection?
Thanks again
Calvin.
____________________________________________________
[EMAIL PROTECTED] wrote:
> How can I grab the cookies from a URLConnection and
> forward it to via my servlet to a client browser?
>
I assume you're talking about reading the *output* cookies from a request that
your servlet made to some other resource, right?
>
> //grab cookie from a URLConnection
> URLConnection uc;
> String name =uc.getHeaderFieldKey("????"); //?????
> String value =uc.getHeaderField("????"); //?????
>
> // how can I know that I am getting all the cookies??
> // how can I know which ones are session tracking??
> // (Session-Id) is this standard??
> //
>
In order to understand HTTP headers and values, you need to read the
appropriate specification documents. In this case, the right spec is RFC 2109
(HTTP State Management Mechanism), which tells you the HTTP header name sent
by a client is 'Set-Cookie'. RFCs are available at
http://www.rfc-editor.org
Note that there can be more than one "Set-Cookie" header in a particular
request, if more than one cookie is being sent. You will want to use the
indexed versions of the getter routines -- something like this:
int n = 0; // Doesn't say for sure that indexes are zero relative
while (true) {
String key = uc.getHeaderFieldKey(n);
if (key == null)
break;
if (key.toUpperCase().equals("SET-COOKIE")) {
String value = uc.getHeaderField(n);
// Cookie encoded in this string per RFC 2109
// You will need to extract all the parameters to
// set up a Cookie object that looks like this one.
}
n++;
}
Session cookie names are not currently standardized, but will be when servlet
engines implement the servlet API version 2.2 specification, at which point
the required name will be "jsessionid".
>
> Cookie c= new Cookie("name","value");
> (HttpServletRequest) req.addCookie();
>
> Calvin
Craig McClanahan
--== Sent via Deja.com http://www.deja.com/ ==--
Share what you know. Learn what you don't.
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html