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.

In reply to Re: http post by 1nickt
in thread http post by bigup401

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.