Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Debugging a POST that won't

by BernieC (Pilgrim)
on Aug 20, 2018 at 17:23 UTC ( [id://1220735]=perlquestion: print w/replies, xml ) Need Help??

BernieC has asked for the wisdom of the Perl Monks concerning the following question:

I can't get a POST to work and I can't figure out why not. I can get and post well enough to get authenticated and otherwise navigate around the site, but this post just won't work. I've tried comparing my _request with the request I see in a WebDeveloper capture of submitting the same POST and as far as I can tell they are identical. I submit all of the same fields that Firefox does {collected from the WD capture - I did't trust that if I just looked at the "view page source" I wouldn't miss one}. The site doesn't give me a hint as to what's wrong, of course, I just get to the appropriate reponse page but with my 'submit' having not happened. Any ideas/tricks for how to figure out what's wrong? It's https:// so I can't go beyond WD to do sniffing of the of actual network data. There aren't any redirects or other oddities: WD says when I click "submit" firefox does a single POST that, as I mentioned, looks pretty much identical to my UserAgeng POST. I have the security tokens correct {it uses two: a security_token POST paramter and a csrf cookie}. I don't know where else to look or what else to try. <p<Just to make it more concrete, the code involved is dead simple:
@fields = (current_step => "New" , next_step => "NewFinal" , [etc ... all the identical fields from both scraping the HTML and lo +oking at WD] ); ); unshift @fields, csrf_token => $csrf_token if $csrf_token ; unshift @fields, security_key => $security_key if $security_key ; $res = $ua->request(POST $_[0], \ @fields) ;
What should I try next?

Replies are listed 'Best First'.
Re: Debugging a POST that won't
by haj (Vicar) on Aug 20, 2018 at 18:53 UTC
    Two ideas:
    • An intermediate step between a direct POST and using Firefox would be automating your Firefox with WWW::Mechanize::Firefox. This might give a hint whether there's some Javascript happening in Firefox which you didn't mimic yet.
    • Also, some websites don't like robots, so you might carefully set your user agent's identification to that of your Firefox.
    Good luck!
Re: Debugging a POST that won't
by markong (Pilgrim) on Aug 22, 2018 at 01:39 UTC

    Are you sure that the entire HTTP dialog is the same? With the help of LWP::ConsoleLogger::Easy you can inspect deeply the entire LWP dialog with the server to double check.

    Also be sure that Firefox web dev tools (you are looking at the net tab I guess) have the "preserve session" option checked (I can't recall the exact name at the moment) to prevent a clean up in between redirects.

    Also check out that the "common" header values are the same e.g.: which UserAgent are you sending with LWP ?

Re: Debugging a POST that won't
by Anonymous Monk on Aug 21, 2018 at 11:19 UTC
    You say everything is identical. It is not. Check the headers

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-25 23:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found