Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Comment on

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

Hi,

I realize you've marked this solved, but stratigery important :)

Yes I am printing the return of the request and this is the error output:

That is not a request. That is information you've already provided. Its like you pay for a drink, bartender says not enough, you still owe me 3 dollars, and you respond with, yes, I already gave you a napkin.

I dont understand what you're trying to do with that code snippet...I am trying to post a file to server for further processing.

I honestly thought you were trying to bake cookies, which is why I asked how much water you've added, because I wanted to make sure you were serious when you said I am trying to bake cookies and I added this much water, because that makes total cents. Total cents!

You should be using the credentials method...To be honest I thought this is better ... CURL...working just fine .. except upload ... I tried to use it but it did not worked :)

Credentials is convenient, shorter and easier to remember and use, than hand-enconding basic auth.

As a bonus, credentials doesn't send username/password unless the remote/target/destination server asks for authentication, and the domain/realm matches.

If credentials "isnt working", your domain/real doesn't match, or your server is broken by not asking for authentication.

Brute force is a terrible way to learn, sourcediving to copy/paste instead of taking 10min to understand 20 lines of code and the corresponding docs.

Anyway , if reject convenience, go big and reject the entire enchilada

#!/usr/bin/perl -- use strict; use warnings; use LWP; my $ua = LWP::UserAgent->new; ## watch "actual" http transactions on stdout $ua->add_handler("request_send", sub { shift->dump; return }); $ua->add_handler("response_done", sub { shift->dump; return }); $ua->show_progress(1); ## on stderr my $urljig = 'http://jigsaw.w3.org/HTTP/Basic/'; $ua->credentials( URI->new( $urljig )->host_port, 'test', 'guest', 'gu +est' ); $ua->get( $urljig ); ## first login (get challenged, authenticate) $ua->post( # then upload "big" file $urljig, { # %form file => [ # form input field name undef, # or '/real/path/to/file/to/upload.txt' "filename to be send that is different from real/path/to/f +ile/to/upload", -content_type => 'text/json', -content => "file contents cause undef doesnt read file", ], }, content_type => 'multipart/form-data', # for the %form ); __END__

When run this produces fruits

GET http://jigsaw.w3.org/HTTP/Basic/
User-Agent: libwww-perl/6.15

(no content)
HTTP/1.1 401 Unauthorized
Connection: close
Date: Thu, 12 Apr 2018 21:49:56 GMT
Server: Jigsaw/2.3.0-beta4
WWW-Authenticate: Basic realm="test"
Content-Length: 261
Content-Type: text/html;charset=ISO-8859-1
Client-Date: Thu, 12 Apr 2018 21:53:28 GMT
Client-Peer: 128.30.52.21:80
Client-Response-Num: 1
Title: Unauthorized
...

GET http://jigsaw.w3.org/HTTP/Basic/
Authorization: Basic Z3Vlc3Q6Z3Vlc3Q=
User-Agent: libwww-perl/6.15

(no content)
HTTP/1.1 200 OK
Connection: close
Date: Thu, 12 Apr 2018 21:49:56 GMT
ETag: "1lkdfte:qoguo8q8"
Server: Jigsaw/2.3.0-beta2
Content-Length: 458
Content-Location: http://jigsaw.w3.org/HTTP/Basic/ok.html
Content-Type: text/html
Last-Modified: Sun, 25 Jun 2000 17:08:58 GMT
Client-Date: Thu, 12 Apr 2018 21:53:28 GMT
Client-Peer: 128.30.52.21:80
Client-Response-Num: 1
Title: Basic Authentication test page
...

POST http://jigsaw.w3.org/HTTP/Basic/
Authorization: Basic Z3Vlc3Q6Z3Vlc3Q=
User-Agent: libwww-perl/6.15
Content-Length: 232
Content-Type: multipart/form-data; boundary=xYzZY

--xYzZY\r
Content-Disposition: form-data; name="file"; filename="filename to be send that is different from real/path/to/file/to/upload"\r
-Content: file contents cause under doesnt read file\r
-Content-Type: text/json\r
\r
\r
--xYzZY--\r\n
HTTP/1.1 405 Method Not Allowed
Connection: close
Date: Thu, 12 Apr 2018 21:49:57 GMT
Server: Jigsaw/2.3.0-beta4
Allow: HEAD,GET,OPTIONS,TRACE
Content-Length: 41
Content-Type: text/html
Client-Date: Thu, 12 Apr 2018 21:53:28 GMT
Client-Peer: 128.30.52.21:80
Client-Response-Num: 1

Method POST not allowed on this resource.

In reply to Re^3: POST file through REST::Client (stratigery) by Anonymous Monk
in thread POST file through REST::Client [SOLVED] by thanos1983

Title:
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?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (5)
    As of 2018-07-17 04:26 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















      Results (354 votes). Check out past polls.

      Notices?