in reply to http post

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.

Replies are listed 'Best First'.
Re^2: http post
by bigup401 (Pilgrim) on Feb 19, 2017 at 17:05 UTC

    thanks hippo thanks 1nickt. 1nickt method has worked for me

    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";

    i will use HTTP::Tiny

Re^2: http post
by bigup401 (Pilgrim) on Feb 19, 2017 at 15:26 UTC

    https://api.kayesms.com/api/v1/sms/send/

    thats the valid link

    i dont know why. all method should work but i think its the api they use HTTP 1/1

Re^2: http post
by bigup401 (Pilgrim) on Feb 19, 2017 at 15:31 UTC

    because direct input works

    https://api.kayesms.com/api/v1/sms/send/?apiKey=9F607F4A-00F2-4B06-A40A-F4B6A574915C&message=Testing%20HTTP%20API&from=test&to=447868756765,44786875676

    all methods of http post ther should work, bt i think the problem with api