Sean Snyders wrote:
> Hi,
> this is a bit oof the topic but has to do with the whole
> internet/java/web-accessing thing.
>
> I'm trying to access a website through a "URLConnection" object.
> This website accepts "form" information with the "POST" method, so I'm using
> "URLConnection.getOutputStream()" to write output to the website.
> (remembering to send
> the content-type as "application/x-www-form-urlencoded" as well).
>
To make sure you're doing a POST request instead of the default GET, you can
cast the URLConnection object you get back to an HttpURLConnection, which
exposes the setRequestMethod() method.
>
> BUT this website only works if you have Cookies enabled in your browser. I'm
> directly
> accessing this website through an "URLConnection" object as said, so the
> question is:
> "how do I handle this problem with the cookie, that get automatically
> handled by the web-browser?"
>
Cookies are sent by the browser in an HTTP header named (of all things :-)
"Set-Cookie". Therefore, you will need to set up such a header, following the
syntax rules for a cookie value. These rules can be found in RFC 2109,
available (among other places) by going to <http://www.rfc-editor.org> and using
one of the search links to locate the text for this RFC.
To fully emulate a browser's handling of cookies, you will need to read the
cookies that are sent to you in responses from this site (the server sends them
in a "Cookie" header), and send them back with any subsequent requests to the
same server. You will also need to make sure you enforce the cookie age
settings, and stop sending cookies back after they have expired. The processing
requirements are listed in the RFC along with the syntax.
>
> Thanx, in advance.
>
> Sean
>
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