in reply to 400 bad request curl post

Automatic conversion of your curl command line to Perl using HTTP::Request::FromCurl (via curl-to-lwp gives the following:

#!perl use strict; use warnings; use WWW::Mechanize; use HTTP::Request; my $ua = WWW::Mechanize->new(); my $r = HTTP::Request->new( 'POST' => 'https://api.blockchain.info/v2/receive/balance_update', [ 'Accept' => '*/*', 'Host' => 'api.blockchain.info:443', 'User-Agent' => 'curl/7.55.1', 'Content-Length' => '169', 'Content-Type' => 'text/plain', ], '{"key":"[your-key-here]","addr":"183qrMGHzMstARRh2rVoRepAd919sGgMHb", +"callback":"https://mystore.com?invoice_id=123","onNotification":"KEE +P", "op":"RECEIVE", "confs": 5}' ); my $res = $ua->request( $r, ); __END__ Created from curl command line curl -H "Content-Type: text/plain" --data '{"key":"[your-key-here]","a +ddr":"183qrMGHzMstARRh2rVoRepAd919sGgMHb","callback":"https://mystore +.com?invoice_id=123","onNotification":"KEEP", "op":"RECEIVE", "confs" +: 5}' https://api.blockchain.info/v2/receive/balance_update

You'll note how the request is different from your setup of the request. Most of that is likely due to not duplicating the parameters faithfully.

Replies are listed 'Best First'.
Re^2: 400 bad request curl post
by bigup401 (Pilgrim) on Dec 06, 2018 at 11:39 UTC

    thanks Corion

      i get same error. when i run the code. Error POSTing https://api.blockchain.info/v2/receive/balance_update: Bad Request at 11.pl line 20.

        If the remote side says Bad Request, then either something is different between the Curl invocation and the Perl invocation, or maybe the Curl invocation fails as well.

        Your next task is to compare what Perl sends with what Curl sends and to edit your code to remove the differences. See LWP::UserAgent::ConsoleLogger and curl -s -v.