POST gets two answers, only got headers from 2nd... Please help!

Hello!
In this attempt to make a software that connects to a webserver (youtube), authenticates and manages a user's address book, I'm using the HttpURLConnection for sending POST data and getting back an answer. Understanding the basics is ok, it works from a Java point of view, but... PLaying with http gets a bit tricky :-)
I've been trying to understand for hours now, and here's the problem: The only HttpURLConnection in use receives a first answer, (with the good data) then a few ms after, it receives a second answer (without that good data).
The headers are read the following way:
Map> headers = http.getHeaderFields();
for (String key : headers.keySet()) {
    for (String value : headers.get(key)) {
        System.out.println(key + ": " + value);
}(see, I've made nothing new)
The system.out.println only outputs the Set-Cookie headers of the second response. A network packet sniffer shows these two responses:
Frame 9 and Frame 18:
{color:#000000}6 {HTTP:1, TCP:0, IPv4:0} 192.168.1.3 208.117.236.70 HTTP HTTP:Request, POST /login{color}
7 {HTTP:1, TCP:0, IPv4:0} 192.168.1.3 208.117.236.70 HTTP HTTP:HTTP Payload, URL: /login
{color:#3366ff}9 {HTTP:1, TCP:0, IPv4:0} 208.117.236.70 192.168.1.3 HTTP HTTP:Response, HTTP/1.1, Status Code = 303, URL: /login{color}
11 {HTTP:1, TCP:0, IPv4:0} 208.117.236.70 192.168.1.3 HTTP HTTP:HTTP Payload, URL: /login
16 {HTTP:3, TCP:2, IPv4:0} 192.168.1.3 208.117.236.70 HTTP HTTP:Request, GET /index
{color:#3366ff}18 {HTTP:3, TCP:2, IPv4:0} 208.117.236.70 192.168.1.3 HTTP HTTP:Response, HTTP/1.1, Status Code = 200, URL: /index {color}
Frame n°
6 being the post request (headers),
7 the payload of the request (i.e. username, password action_login, etc.),
9 is the the answer containing the needed Set-Cookies ("LOGIN_INFO"),
11 the payload of that answer (contains nothing relevant),
16 hmm not sure about its purpose,
18 is the "second" response to the post request.
Frame 18 does contain a few Set-Cookie headers, but these are useless (i.e. GEO tag, etc. which are different between every request). However, I can't find a way to "prevent" my instance of HttpURLConnection to recover further responses... I tried to put
setRequestProperty("Connection", "close");instead of "keep-alive", but no, doesn't help :(
Then I thought it was a header's fault in frame 9: "Location" which would impose a redirect and did expect the following code to prevent "getting" or whatever send another response:
setFollowRedirects(false); Ok. It's a bit early to call it a happy end... I really need help for this!
Thanks a lot for your time!
Edited by: Neurone-shortage on Feb 7, 2009 4:16 AM

Have a look at the status code of your POST request. It's 303 (See other), which is a redirect. Either your request data is missing some data, or you are sending your request to a wrong URL.
I think, the redirect points to /index, that's why HttpUrlConnection transparently request /index for you, which results in the second response.
Cheers
Henrik

Similar Messages

Maybe you are looking for

  • Using time capsule to backup FCP files on External Lacie drives

    Has anyone done this with any measure of success? I have my FCP projects on 3 to 4 external Lacie drives and I want to back them up onto my 1 TB TC. It seems TC only backs up the internal HD and not external HD's. Is my only option to drag the data o

  • About account assignment group in Sales Order.

    Hi gurus, I am working in SD for the first time and I am facing below problem 1. Material code was created  with account assignment group (MVKE-KTGRM)  as blank (Sales Org 2 view) 2. Later this material was entered in Sales Order. 3. Subsequently Sal

  • Front Row on Snow Leopard has audio out of sync on movies and TV shows and some movies wont show images.

    I have an iMac Core Duo 2GHz (yes, first Intel iMac). I have Snow Leopard v10.6.8 (latest/last MacOS version I could load) with the most recent Security Update (2013-003). I have two issues with Front Row: • Some of the movie files will not show the

  • Front Row Displays all my vids as "Movies"

    I want my Music Videos to be filed under "Music Videos" and my TV Shows under "TV Shows" and my Movies under "Movies" and my Podcasts under "Podcasts"... why do all my vids (no matter what they are) show up under movies? The only things that catagori

  • ORAENV file to be disabled

    Hi, Oracle Version:10.2.0.3 Operating system: Linux Here i have a doubt .I was unable to connect to database with oracle OS user until i run the oraenv file . How can i disable oraenv file in order to connect to the database with out running the orae