This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
I am using the java.net.URL object, for both GET and POST pages. And for the most part, everything works. However, with some pages, the URL will forward to another page, and I wind up reading zero bytes, from the URL object.
Question: How do a detect that the page has been forwarded? And how do I know what URL, has it been forwarded to? (so that I can follow it)
If you cast your URLConnection object to an HttpURLConnection then you can call the setInstanceFollowRedirects(false) method. Not sure what happens when a redirect happens, I haven't used this method myself, but you could experiment with known redirecting URLs.
Edit: but I see you are asking about forwarding, not redirecting. You shouldn't have a problem of not being able to read data if the server forwards your request. If you do, maybe there's something wrong on the server. At any rate there's no way for the client to find out about forwarding. [ August 18, 2008: Message edited by: Paul Clapham ]
I think the only way for you to know it happens is to be given the 302 (or similar) code as an exception, and to get the new URL from one of the returned headers. Then you'd have to send the new request yourself.
By the way POST requests can't be redirected, because a redirect always requires the client to send a GET request as a response to the 302 code.