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

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Dear fellow Monks,

I'm using LWP::UserAgent to simulate users on a website. The problem I have is that UserAgent behavior after POSTing appears to be different to Netscape's.

When my web application instructs Netscape to redirect (by sending back a 302 Moved message) Netscape will generate a new request which will be a GET request, and discarding the POST parameters of the original request. Netscape, thus, transforms the POST request into a GET request with no content after redirection.

LWP::UserAgent, to begin with, won't follow redirects after posting unless you override the LWP::UserAgent::redirects_ok method to return True for POST requests. Once you do this its behavior for POST redirects will be to issue a new POST request with the same payload (content) of the original request. UserAgent's behavior, thus, is to reissue the exact same request, to the new URL.

I don't know what the HTTP RFC says, but I guess it wouldn't matter, since Netscape's has to be the de-facto standard.

This difference in behaviors is preventing me from reproducing exact user request sequences because my web application assumes that redirects after posting carry no parameters, which is not the case for UserAgent redirects.

I've modified LWP::UserAgent to mimick Netscape's behavior, and now my test sequences pass.

My questions are, do you think this is a bug in LWP::UserAgent, and what the RFC says? A coworker of mine suggests that I submit a patch to LWP for it to do "Netscape emulation". Who do you think is right? I guess the behavior of IE is the same as Netscape's since our web application works fine on it, too.



In reply to Redirect after POST behavior in LWP::UserAgent differs from Netscape's? by gregorovius

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (13)
    As of 2018-06-18 18:19 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (110 votes). Check out past polls.