bigup401 has asked for the wisdom of the Perl Monks concerning the following question:
anyone can help me with this. am getting this error you need a request object, not a http::response. am new to curl post
this is the curl script
curl https://site.com/api/inforequests -H "Authorization: Token xert34 +5llkd736gdy3" \ -d name=+80000000001 \ -d country=BXC \ -d email=3000
#!/usr/bin/perl use LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->agent("MyApp/0.1"); $url = "https://site.com/api/inforequests"; my @headers = ("Authorization: Token xert345llkd736gdy3"); foreach my $ml(@headers) { $auth = $ml; } my $data = { name => 'john', country=> 'ca', email=> 'john@email.com', }; my $req = HTTP::Request->new(POST => '$url', 'Content-type' => 'application/json', 'Authorization' => "$auth" ); $req->content_type('application/json'); $req->content($data); my $res = $ua->request($req); if ($res->is_success) { print $res->content; } else { print $res->status_line, "n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: curl http post
by 1nickt (Canon) on Mar 25, 2017 at 17:28 UTC | |
by beech (Parson) on Mar 25, 2017 at 18:48 UTC | |
by 1nickt (Canon) on Mar 25, 2017 at 19:17 UTC | |
by bigup401 (Pilgrim) on Mar 25, 2017 at 21:21 UTC |