Hi bigup401,
HTTP code 411 means The server refuses to accept the request without a defined Content-Length. You're probably getting this because you are attempting to make a POST request but not sending any body, while the API you are querying expects a GET request with params in the URL query string (which you've sorta done).
Update: It's unclear whether you are supposed to be making a POST or a GET request. ( Note that the URL you have has been replaced, according to the 301 response I got when testing further. The updated URL for the API endpoint is https://www.website.com/api/v1/sms/send. Most user agents will follow redirects but you might as well update the URL in your source code. This does suggest that you are not working from the latest documentation for the API you are attempting to use, however.)
Here are two examples that are more like what you need (using HTTP::Tiny, which can simplify your life considerably for simple tasks). Showing with GET and with POST:
use strict; use warnings;
use HTTP::Tiny;
my $ua = HTTP::Tiny->new;
my $url = "https://www.website.com/api/v1/sms/send";
my $data = {
apiKey => "edftr44456",
from => "demo",
to => "447777777777",
message => "demo HTTP API",
};
my $params = $ua->www_form_urlencode( $data );
my $response = $ua->get( $url . '/?' . $params );
print $response->{'status'} . "\n";
use strict; use warnings;
use HTTP::Tiny;
my $ua = HTTP::Tiny->new;
my $url = "https://www.website.com/api/v1/sms/send";
my $data = {
apiKey => "edftr44456",
from => "demo",
to => "447777777777",
message => "demo HTTP API",
};
my $response = $ua->post_form( $url, $data );
print $response->{'status'} . "\n";
Unfortunately both these code examples produce an HTTP status code of 404, which suggests that you aren't using the correct URL/params for the API.
Hope this helps!
The way forward always starts with a minimal test.
|