Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: HTTP 302 error now??

by IlyaM (Parson)
on May 22, 2002 at 16:10 UTC ( [id://168497]=note: print w/replies, xml ) Need Help??


in reply to HTTP 302 error now??
in thread LWP, extract_cookies, etc.

Very helpful, but now I have that crazy HTTP 302 error.

The problem with HTTP error is caused by default behaviour of LWP::UserAgent. Sorry I forgot about it when I wrote my version of this script. LWP::UserAgent by default doesn't handles redirects after POST requests automatically. If you have not very old version of LWP::UserAgent you can redifine this behaviour using following sniplet:

push @{ $ua->requests_redirectable }, 'POST';

Also, Ilya you had simple_request on the second post. Did you mean to have just 'request' there?

I'm sorry. I did mean $ua->request instead of $ua->simple_request.

And do I not need "my $request = " on the first "$ua->request(POST..." line?

Since you do not use response object from first request there is no need to store it in any variable.

I have updated script in my first node with all fixes.

--
Ilya Martynov (http://martynov.org/)

Replies are listed 'Best First'.
No more 302 error, just no cookie info with POST?
by inblosam (Monk) on May 22, 2002 at 20:16 UTC
    IlyaM: You have been great!

    It still doesn't post the data and gives me what seems to be the screen that would show up if someone was not logged in. I used your newest code (just a note, I had to add a ");" on the end of line 12) and it gave me the following in the header of the page returned:
    HTTP/1.1 200 OK Connection: close Date: Wed, 22 May 2002 19:56:15 GMT Server: Microsoft-IIS/5.0 Content-Type: text/html Expires: 0 Client-Date: Wed, 22 May 2002 19:58:47 GMT Client-Response-Num: 1 Page-Completion-Status: Normal Page-Completion-Status: Normal Set-Cookie: CFGLOBALS=HITCOUNT%3D46%23LASTVISIT%3D%7Bts+%272002%2D05%2 +D22+12%3A56%3A16%27%7D%23TIMECREATED%3D%7Bts+%272002%2D05%2D20+23%3A4 +7%3A29%27%7D%23; expires=Sun, 27-Sep-2037 00:00:00 GMT; path=/; Set-Cookie: LASTVISIT=%7Bts+%272002%2D05%2D22+12%3A56%3A16%27%7D; expi +res=Sun, 27-Sep-2037 00:00:00 GMT; path=/; Set-Cookie: SID=99999999999999999999; expires=Fri, 21-Jun-2002 12:56:1 +6 GMT; path=/; Title: Page Title
    The rest of the page comes up with their default signup form (when you are in the member area and not logged in?). Any ideas? It doesn't seem like the cookie is being passed with the second POST request. THANKS!

    Edit by dws for code tags and formatting

      It is hard to say what is wrong. You should try to turn on debug output in LWP::UserAgent. See LWP::Debug. For example if you add following code into your script it will turn on all debug prints inside LWP::UserAgent.
      use use LWP::Debug qw(+);
      Particullary you will be able to see all redirects and all headers. It will show you if you do recieve cookie in response for first request and if it sent back later in second request.

      --
      Ilya Martynov (http://martynov.org/)

        I turned on LWP debug and the only thing that seems like an error is this:

        LWP::UserAgent::_need_proxy: Not proxied


        Is that the problem why my POST is not POSTing? Or is there something else to look for in the debug results? THANKS!!

        Michael Jensen
        michael at inshift.com
        http://www.inshift.com

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://168497]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-03-28 18:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found