[EMAIL PROTECTED] wrote:

> 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

Interesting ... this is the first line of an HTTP response (see the HTTP protocol spec 
for more info), which in fact does not have a header name in front of
it.

For your purposes, starting at index value 1 is probably the right answer.

>
> 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=/

This is a cookie; presumably a session ID cookie from some servlet engine based on the 
cookie name.

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

According to the Javadocs, you're supposed to stop iterating as soon as you get null 
values -- that's how you know you have hit the last header that was
included.

>
> 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?
>

What's wrong with URLConnection.setRequestProperty(String key, String value)?  For 
your scenario, key would be "Set-Cookie" and value would be the string you
grabbed above (at index position 3 in your trace).

If you are connecting to an "http://xxxxxx" type URL (which is likely, since cookies 
are an HTTP thing), you will also need to set some other headers, and
perhaps change the request method (default is GET).  The easiest way to do this is to 
cast the URLConnection to an HttpURLConnection, which gives you access to
some additional functionality that is only available when you are talking HTTP.

>
> Thanks again
> Calvin.
>

Craig McClanahan

___________________________________________________________________________
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

Reply via email to