in reply to Attempting to POST a file to local server

Well this was fun but I found out why! Turns out an underscore in the 'Content_Type' field rather than a dash makes both Perl and the server unhappy

Best -- cookersjs
  • Comment on Re: Attempting to POST a file to local server

Replies are listed 'Best First'.
Re^2: Attempting to POST a file to local server
by tobyink (Canon) on May 11, 2017 at 08:22 UTC

    But the code in your original post already has an underscore.

      I too found the phrasing confusing but it is correct as stated

      A value of form_data (an error) is treated as "application/x-www-form-urlencoded"

      A value of form-data is treated as "multipart/form-data"

      #!/usr/bin/perl -- use strict; use warnings; use LWP; my $ua = LWP::UserAgent->new; $ua->add_handler("request_send", sub { shift->dump; return }); $ua->add_handler("response_done", sub { shift->dump; return }); $ua->timeout( 0.1 ); my $res = $ua->post('http://localhost:8012/', #~ Content_Type => 'form_data', ## treated as "application/x-www-f +orm-urlencoded" Content_Type => 'form-data', ## treated as "multipart/form-data" #~ Content_Type => 'multipart/form-data', Content => [ Filedata => [ __FILE__, 'Hello.txt', Content_Type => 'text/plain', ], submit => 'Submit', ], );

      BTW: Nice that you are back.

      Regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

      Furthermore I consider that Donald Trump must be impeached as soon as possible

        Thanks.

        Thats something you /msg karlgoethebier