bigup401 has asked for the wisdom of the Perl Monks concerning the following question:
thanks to poj who helped me on this 400 BAD REQUEST to structure the request. then I came up with header structure and body structure. now am trying to make the request but am getting 500 Not a SCALAR reference
#!/usr/bin/perl use strict; use warnings; use HTTP::Request::Common qw(POST); use LWP::UserAgent; use Digest::SHA qw(hmac_sha256_hex); use URI; use Encode; use HTTP::Headers; use HTTP::Message; my $nonce = 1000; my $url = "https://localbitcoins.com"; my $api_endpoint = "/api/merchant/new_invoice/"; my $hmac_key = "sdfsdfdsfdsfy"; my $hmac_secret = "sdfdsfdsf"; my %params = ( currency => 'USD', amount => '500', description => 'HEY', internal => '0', ); my $uri = URI->new(); $uri->query_form( \%params ); my $post_params_urlencoded = $uri->as_string; $post_params_urlencoded =~ s/^[?]//; printf "params = %s\n", $post_params_urlencoded; my $message = encode('utf8',$nonce.$hmac_key.$api_endpoint.$post_p +arams_urlencoded); my $signature = uc hmac_sha256_hex($message, $hmac_secret); printf "sig = %s\n",$signature; print"\n"; print "headers are:\n"; my $headers = HTTP::Headers->new( 'Apiauth-Key' => $hmac_key, 'Apiauth-Nonce' => $nonce, 'Apiauth-Signature' => $signature, ); my $body = HTTP::Message->new($headers, $post_params_urlencoded); print $body->as_string; my $ua = LWP::UserAgent->new; $ua->agent("MyApp/0.1 "); my $req = HTTP::Request->new(POST => $url); $req->content($body); my $res = $ua->request($req); print "Content-type: text/plain\n\n"; if ($res->is_success) { print $res->content; } else { print $res->status_line, "\n"; }
Output
params = currency=USD&amount=500&internal=0&description=HEY sig = FE5B4A4A66FEAB0C1216B59C81BC2FD2CA5DC4459D84CF9A7DD8EFE37242E59A headers are: Apiauth-Key: sdfsdfdsfdsfy Apiauth-Nonce: 1000 Apiauth-Signature: FE5B4A4A66FEAB0C1216B59C81BC2FD2CA5DC4459D84CF9A7DD +8EFE37242E 59A currency=USD&amount=500&internal=0&description=HEY Content-type: text/plain 500 Not a SCALAR reference Press any key to continue . . .
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: 500 Not a SCALAR reference
by 1nickt (Canon) on Jan 08, 2019 at 01:44 UTC | |
|
Re: 500 Not a SCALAR reference
by stevieb (Canon) on Jan 07, 2019 at 21:57 UTC | |
by bigup401 (Pilgrim) on Jan 07, 2019 at 22:10 UTC | |
by stevieb (Canon) on Jan 07, 2019 at 22:19 UTC | |
by marto (Cardinal) on Jan 07, 2019 at 22:30 UTC | |
by stevieb (Canon) on Jan 07, 2019 at 22:31 UTC | |
by bigup401 (Pilgrim) on Jan 07, 2019 at 22:34 UTC | |
by poj (Abbot) on Jan 08, 2019 at 07:57 UTC | |
|