>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.
Isn't setting the content-type as "application/x-www-form-urlencoded"
achieving the same
result as setting the RequestMethod to "POST" ?
>> 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.
The thing is: the other web-site I'm POST-ing information to, requires me to
have have cookies
enabled because it wants to save information (sessionid for session
management, I think I'm dealing
with a servlet on the other end ) on my computer while I'm busy on the
website. I think it only wants to
put information once onto my computer and I don't think it uses that info at
all (I could be wrong).
Now, once I write to the POST information to the URLConnection and closes
the stream. I open the
input stream of the URLConnection and then read the response of the other
web-site. It is then a
nicely HTML formatted message saying that I need Cookies enabled.
- So when do I actually receive this Cookie ?
- If I set the Header "Set-Cookie", will the Cookie be read in from the
inputstream of
URLConnection before I receive the response (HTML stuff) ?
>>
>> Thanx, in advance.
>>
>> Sean
>>
>
>Craig McClanahan
THANX AGAIN
Sean Snyders.
___________________________________________________________________________
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