bubble bubble - 2 months ago 14
Perl Question

Simple API request not working - 403 error

I am trying to run a simple API request from a perl script. But it seems not working. Same request if copied to web browser works without any problem.

use strict;
use warnings;

use LWP::Simple;

my $query = 'http://checkdnd.com/api/check_dnd_no_api.php?mobiles=9944384761';

my $result = get($query);
print $result."\n";

when I use
- it gives 403 error.


If you take a look at the body of the response (i.e. not only at the status code 403) you will find:

The owner of this website (checkdnd.com) has banned your access based on your browser's signature (2f988642c0f02798-ua22).

This means that it is blocking the client because it probably looks too much like a non-browser. For this site a simple fix is to include some User-Agent header. The following works for me:

my $ua = LWP::UserAgent->new;
$ua->default_header('User-Agent' => 'Mozilla/5.0');
my $resp = $ua->get('http://checkdnd.com/api/check_dnd_no_api.php?mobiles=9944384761');
my $result = $resp->decoded_content;

The site in question seems to be served by Cloudflare which has some thing they call "Browser Integrity Check". From the support page for this feature:

... looks for common HTTP headers abused most commonly by spammers and denies access to your page. It will also challenge visitors that do not have a user agent or a non standard user agent (also commonly used by abuse bots, crawlers or visitors).