EPSS has asked for the wisdom of the Perl Monks concerning the following question:
I am attempting to perform the following curl command in perl and I can't figure out what I doing wrong. Any suggestions you have would be appreciated. Here is my non-working perl code and working php code. In both the perl and php scripts the site returns a success status but in the perl code they don't get the data and webhook.
curl -X POST https://api.mysite.com/2022-01-08/enrich/upload -u any_string:{secure_token} -d data="testme@mysite.com" -d webhook="http://mywebhook.com/"Non-Working Perl Code
#!/usr/bin/perl use warnings; use strict; use LWP::UserAgent; use Data::Dumper; my $ua = LWP::UserAgent->new(); my $url = "https://api.mysite.com/2022-01-08/enrich/upload"; my $data = 'testme@mysite.com'; my $webhook = "http://mywebhook.com/"; my $user = "any_string"; my $pwd = "{secure_token}"; my $content_type = "form-data"; $ua->credentials($user, $pwd); my $response = $ua->post($url, Content_Type => $content_type, Content +=> [data => $data, webhook => $webhook] ); my $content = $response->as_string(); print ($content);
Working PHP Code
<?php $url = "https://api.mysite.com/2022-01-08/enrich/upload"; $data = "testme@mysite.com"; $webhook = "http://mywebhook.com/"; $user = "any_string"; $pwd = "{secure_token}"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_USERPWD, "$user:$pwd"); $data = "data=$data&webhook=$webhook"; curl_setopt($curl, CURLOPT_POSTFIELDS, $data); //for debug only! curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $resp = curl_exec($curl); curl_close($curl); var_dump($resp); ?>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Asking for help with simple api post via perl
by Corion (Patriarch) on Mar 16, 2022 at 21:49 UTC | |
by EPSS (Initiate) on Mar 16, 2022 at 22:41 UTC |