Reputation: 3324
I use Curl -dump-header but i get also access denied. Is there any way to connect and get html code?
Curl --dump-header - https://www.gearbest.com/car-charger/pp_009363232829.html
> HTTP/2 403 server: AkamaiGHost mime-version: 1.0 content-type:
> text/html content-length: 314 cache-control: max-age=60 expires: Sat,
> 22 Jun 2019 22:25:51 GMT date: Sat, 22 Jun 2019 22:24:51 GMT
> set-cookie: AKAM_CLIENTID=7e3530d888ae97fef4ad26c997d733c5;
> expires=Mon, 31-Dec-2038 23:59:59 GMT; path=/; domain=.gearbest.com
> vary: User-Agent
<HTML><HEAD>
<TITLE>Access Denied</TITLE>
</HEAD><BODY>
<H1>Access Denied</H1>
You don't have permission to access "http://www.gearbest.com/car-charger/pp_009363232829.html" on this server.<P>
Reference #18.85451502.1561242291.25f21039
</BODY>
</HTML>
If i go to the page using the browser it works fine. I just want to get the html code of the page. any help appreciated.
Upvotes: 3
Views: 14279
Reputation: 2367
Here is you PHP code modified, and it works perfectly fine (tested):
<?php
$curl1 = curl_init();
$url = "https://gearbest.com/car-charger/pp_009363232829.html";
curl_setopt($curl1, CURLOPT_URL, $url);
curl_setopt($curl1, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($curl1, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0');
curl_setopt($curl1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl1, CURLOPT_FOLLOWLOCATION, true);
$str = curl_exec($curl1);
echo $str;
Few notes:
curl_exec()
to return HTML code, but without setting CURLOPT_RETURNTRANSFER
option first that would not happenwww.
if you omit it), and to handle that properly you need to set CURLOPT_FOLLOWLOCATION
optionUpvotes: 1