1

I thought I'm getting quite well with PHP/curl, but here I don't know what's all about?

[GET] https://www.olx.pl can be fetched with no problems, but I can't get JSON requesting: [GET] https://www.olx.pl/i2/ajax/ad/getcontact/?id=477486803&type=phone

In browser it's fine, in POSTMAN it's fine (all security options off).

The code I execute:

$urlForTel = "https://www.olx.pl/i2/ajax/ad/getcontact/?id=477486803&type=phone";
$headers = array(
    'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0'
);
$ch = curl_init();
// curl_setopt($ch, CURLOPT_PROXY, $proxy_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_URL, $urlForTel);
$result=curl_exec($ch);

The code just stops and doesn't go forward... As you see I tried many different options (certs, proxy, with headers and without). However when you change e.g. last digit in ID in param (requesting non existing asset), it returns HTML correctly...

I tried curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); with cert downloaded and with/without useragent as well...

4
  • 2
    Add curl_error($ch) to see if the request returns any errors.
    – Jerodev
    Commented Aug 23, 2018 at 7:14
  • The behavoir remains the same... Nothing happens on stdout. I added echo curl_error($ch) after curl_exec. Commented Aug 23, 2018 at 7:39
  • Got anything in your php error log?
    – Jerodev
    Commented Aug 23, 2018 at 7:42
  • Unfortunately nothing... Does it work using CURL with your php configuration? Commented Aug 23, 2018 at 7:46

1 Answer 1

1

I could reproduce your issue with the given code, and managed to make it work by simply adding an Accept header like this:

$headers = array(
    'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0',
    'Accept: application/json',
);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.