in reply to Re: Bug in LWP? Missing cookie
in thread Bug in LWP? Missing cookie

I am a bit confused but also interested to see how it worked. Do you want to say that: $ua->post("https://panel.dreamhost.com/index.cgi", \@fields); does not work?

Replies are listed 'Best First'.
Re^3: Bug in LWP? Missing cookie
by BernieC (Pilgrim) on Aug 05, 2018 at 15:58 UTC

    No the other way: just putting in @fields or , as it is in the docs, name=> value, name=>value, ... didn't work. What did work is using the reference: \@fields. They both send the POST variables and values, except: the reference one also includes a 'content' string which is all the variables concatenated and html encoded. That made the difference and *everything* magically worked. I wish I could explain more about what made the difference or why it worked.

    How I found it is that I compared every byte that my browser sent with what my Perl program sent. They were {essentially} identical except that I noticed that the browser had a content-length of 76 {and the data string i mentioned above} and Perl had a content-length of 0. I pored over the docs and blundered across a mention of the content-length stuff in HTTP::Request::Common, tried it and discovered that that made Perl sent the content-string and it all worked. If someone understands this bit of the POST formatting, I'd be happy to better understand what was/is going on. But for now, all I can say is that using the reference works and using the array doesn't.

      Some general thoughts. I don't know much about this general topic, but looking at HTTP::Request::Common, I see that while the discussion therein of the POST method has many text examples in the
          POST $url, Header => Value,...
          POST $url, $form_ref, Header => Value,...
      format, the actual function invocation examples all look like
          $request = HTTP::Request::Common::POST( $url, [ %data ] );
      or
          $ua->request(POST 'http://somewhere/foo', [foo => bar, bar => foo]);
      etc., so this "array" (which might be better thought of as a list of paired items) is always passed as an array reference.

      Because it's easy in Perl for a function to look at its arguments at run-time and determine if an argument is a simple scalar or some kind of reference and take alternative action accordingly, functions with complex argument lists are often written so that a particular function  foo() can be called as any of
          foo($string, [ qw(list of stuff) ]);
          foo($string, $another_string, [ %hash ]);
          foo($string, $second_string, $third_string, \@array);
      etc., where the expressions  [ qw(list of stuff) ] and  [ %hash ] and  \@array all produce array references.

      BTW:   Please don't post text with fields like [some text here] because the  [ ] (square brackets) are markup and just create links to nowhere. (Update: Please see Writeup Formatting Tips and Markup in the Monastery.)


      Give a man a fish:  <%-{-{-{-<

      I agree with AnomalousMonk:

       text examples in the
          POST $url, Header => Value,...
          POST $url, $form_ref, Header => Value,...
      format, 
      
      (Update1: deleted my wrong conclusion)

      these are just text / informal examples. They are not actual Perl.

      So, the perl function invocation is   $ua->request(POST 'http://somewhere/foo', [foo => bar, bar => foo]); in your case  $ua->request(POST 'http://somewhere/foo', \@fields)

      In this Monastery there is no magic (maybe only M.A.G.I.C. or just M-A-G-I-C (re: B-I-N-G-O) ), that's why I am here

      p.s. Kudos on your meticulous investigation skills ++ (re: headers byte count).

        They are not actual Perl.

        But it is. And as the name $form_ref implies, one should provide a reference of the form data. (Elsewhere shows this to be an reference to a array of alternating keys and values.)