I'm trying to upload a file, via REST. but I keep getting a 500
Not a SCALAR reference
I'm read numerous articles as to why...I can only speculate that my data/content is not correctly formatted.
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;
}
Here is what the request looks like...
$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' );
And here is the response
$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' );
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.