leefp has asked for the wisdom of the Perl Monks concerning the following question:
Here is what the request looks like...use strict; use warnings; use diagnostics; use IO::Socket::SSL qw( SSL_VERIFY_NONE ); use LWP::UserAgent; use Data::Dumper; use MIME::Base64; use JSON; my $json = JSON->new; my $ua = LWP::UserAgent->new(); $ua->ssl_opts( SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE +, SSL_hostname => '', verify_hostname => 0 ); $ua->default_header('Content-Type' => 'application/json' ); $ua->default_header('Content_Type' => 'form-data;boundary=xYzZY'); $ua->default_header('Authorization', "Basic " . encode_base64("adm +in:password")); $ua->timeout(600); my $file = ["/tmp/test_image.tgz.bin"]; my $url = "https://10.248.179.31/api/rest/software_package"; my $header = ['Content-Type' => 'form-data;boundary=xYzZY']; my $request = HTTP::Request->new("POST", "$url", $header, $file); # my $request = HTTP::Request->new("GET", "${url}?select=*", undef) +; print Dumper $request; my $res = $ua->request($request); if($res->is_success) { my $data = $json->decode($res->decoded_content); print Dumper $data; } else { print Dumper $res; }
And here is the response$VAR1 = bless( { '_headers' => bless( { 'content-type' => 'form-data;b +oundary=xYzZY' }, 'HTTP::Headers' ), '_uri' => bless( do{\(my $o = 'https://10.248.179.31/ +api/rest/software_package')}, 'URI::https' ), '_content' => [ '/tmp/test_image.tgz.bin' ], '_method' => 'POST' }, 'HTTP::Request' );
$VAR1 = bless( { '_headers' => bless( { 'content-type' => 'text/plain' +, 'client-warning' => 'Internal +response', '::std_case' => { 'client-date +' => 'Client-Date', 'client-warn +ing' => 'Client-Warning' }, 'client-date' => 'Fri, 14 Dec +2018 21:18:16 GMT' }, 'HTTP::Headers' ), '_rc' => 500, '_request' => bless( { '_headers' => bless( { 'author +ization' => 'Basic YWRtaW46UGFzc3dvcmQxMjMh ', '::std_ +case' => { + 'if-ssl-cert-subject' => 'If-SSL-Cert-Subject' + }, 'conten +t-type' => 'form-data;boundary=xYzZY', 'user-a +gent' => 'libwww-perl/6.26' }, 'HTTP: +:Headers' ), '_uri' => bless( do{\(my $o = +'https://10.248.179.31/api/rest/software_package')}, 'URI::https' ), '_content' => [ '/tmp/test_ima +ge.tgz.bin' ], '_method' => 'POST' }, 'HTTP::Request' ), '_content' => 'Not a SCALAR reference at /usr/lib/per +l5/vendor_perl/5.18.2/LWP/Protocol/http.pm line 256. ', '_msg' => 'Not a SCALAR reference' }, 'HTTP::Response' );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: LWP::Useragent - File Upload
by bliako (Abbot) on Dec 14, 2018 at 21:41 UTC | |
by leefp (Initiate) on Dec 20, 2018 at 19:48 UTC | |
by leefp (Initiate) on Dec 20, 2018 at 19:49 UTC | |
by bliako (Abbot) on Dec 20, 2018 at 22:04 UTC | |
|
Re: LWP::Useragent - File Upload
by poj (Abbot) on Dec 15, 2018 at 14:14 UTC | |
by leefp (Initiate) on Dec 20, 2018 at 19:51 UTC | |
by poj (Abbot) on Dec 20, 2018 at 20:24 UTC | |
by Anonymous Monk on Jun 23, 2020 at 13:02 UTC | |
by choroba (Cardinal) on Jun 23, 2020 at 14:39 UTC | |
| |
by yourself (Novice) on Feb 03, 2021 at 03:22 UTC |