sannag has asked for the wisdom of the Perl Monks concerning the following question:
I am trying do a post request using REST::Client and keep getting 400 error. Here is what the client is expecting
Post: /api/m1/token
Hots: https://api.xxx.com
Content-Type: application/x-www-form-urlencoded
grant=client_credentials&partner={partner}&client={client}&secret={secret}
based on the above information what am I doing wrong. Here is the code
use Data::Dumper; use REST::Client; sub generate { my $tokenURI = 'https://api.xxx.com/api/m1/token'; displayMsg( "Establishing connection................"); my %json_body = (grant => 'client_credentials', partner => ‘dfjkdjfdkdjkdkdjfdk’, client => 'dkfjdlfjdlfkjlj', client => 'dfkljflsfjlajflafjlsdkfjdskl=', # ne +ed encoding that is = will be %3D ); $restClient->addHeader("Content-Type", "application/x-www-form-urlen +coded"); my $bodyData = encode_json(\%json_body); $restClient->POST($tokenURI, $bodyData); print Dumper($restClient); if ($restClient->responseCode() eq '200') { displayMsg ("Sucessfull "); my $token = decode_json($restClient->responseContent()); my $tokenAccess = $token->{'access_token'}; my $tokenType = $token->{'token_type'}; return $tokenType.' '.$tokenAccess; } else { displayMsg ( "Failed ."); displayMsg( 'Response status: ' . $restClient->responseCode()); foreach ( $restClient->responseHeaders() ) { print 'Header: ' . $_ . '=' . $restClient->responseHeader($_) . "\n +"; } exit 1; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: REST::Client POST error
by roboticus (Chancellor) on Aug 30, 2017 at 22:07 UTC | |
by sannag (Sexton) on Aug 30, 2017 at 22:27 UTC | |
by sannag (Sexton) on Aug 31, 2017 at 13:59 UTC | |
|
Re: REST::Client POST error
by huck (Prior) on Aug 30, 2017 at 23:58 UTC | |
by sannag (Sexton) on Aug 31, 2017 at 13:53 UTC | |
|
Re: REST::Client POST error
by AnomalousMonk (Archbishop) on Aug 31, 2017 at 00:19 UTC | |
by sannag (Sexton) on Aug 31, 2017 at 14:32 UTC | |
by AnomalousMonk (Archbishop) on Aug 31, 2017 at 16:37 UTC | |
|
Re: REST::Client POST error
by beech (Parson) on Aug 31, 2017 at 00:26 UTC | |
by sannag (Sexton) on Aug 31, 2017 at 13:56 UTC |