HERE IS THE PHP CODE WHICH I FOLLOWED AND WANT TO WRITE IT IN PERL

$hmac_key = 'your hmac key'; $hmac_secret = 'your secret'; $search = array('.'); $replace= array(''); $mt = microtime(true); $mt = str_replace($search,$replace,$mt); $nonce = $mt; $api_endpoint = '/api/myself/'; $url = 'https://localbitcoins.com'.$api_endpoint; $get_or_post_params_urlencoded = ''; $message = $nonce . $hmac_key . $api_endpoint . $get_or_post_params_ur +lencoded; $message_bytes = utf8_encode($message); $signature = mb_strtoupper( hash_hmac( 'sha256', $message_bytes, $hmac +_secret ) ); $ch = curl_init('https://localbitcoins.com'.$api_endpoint); $options = array( CURLOPT_RETURNTRANSFER => 1, CURLOPT_TIMEOUT => 30, CURLOPT_HTTPHEADER => array( 'Apiauth-Key:'.$hmac_key, 'Apiauth-Nonce:'.$nonce, 'Apiauth-Signature:'.$signature ), ); curl_setopt_array($ch, $options); $result = curl_exec($ch); curl_close($ch); echo $result;

NOW HERE IS WAT I WROTE. BUT AM GETTING 400 BAD REQUEST

#!/usr/bin/perl -w BEGIN { print "Content-type: text/plain\n\n"; } use LWP::UserAgent; use Time::HiRes qw(gettimeofday); use Digest::SHA qw(sha256); use URI; use URI::QueryParam; use CGI::Carp qw(fatalsToBrowser); my $uri = URI->new(); my $nonce = int (gettimeofday * 1000); $url = "https://localbitcoins.com"; $api_endpoint = "/api/merchant/new_invoice/"; $hmac_key = "sfsdfdsfdsfsdf"; $hmac_secret = "fsdfdsfdsfd"; %params = ( currency => 'USD', amount => '500', description => 'HEY', internal => '0', ); $uri->query_param($_, $params{$_}) for keys %params; $post_params_urlencoded = $uri->query; $message = ($nonce.$hmac_key.$api_endpoint.$post_params_urlencoded); my $signature = unpack("H*", sha256($message, $hmac_secret)); my $ua = LWP::UserAgent->new; my $res = $ua->post( $url.$api_endpoint, "Apiauth-Key" => "$hmac_key", "Apiauth-Nonce" => "$nonce", "Apiauth-Signature" => "$signature", ); if ($res->is_success) { print $res->content; } else { print $res->status_line, "\n"; }

In reply to 400 BAD REQUEST by bigup401

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, details, 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, summary, 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.