Почему парсит командой, а через curl php нет?

Есть запрос такого формата который отлично срабатывает:
curl "https://forklog.com/wp-content/themes/newForklog/ajaxposts.php" 
-H "Referer: https://forklog.com/news/" 
-H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" 
-H "X-Requested-With: XMLHttpRequest" 
-H "Connection: keep-alive" 
--data "action=PostsByCat&offset=12&postperpage=12&category=news/&tag=news/"

Но вот если сделать аналогичное через curl php, то выдает пустоту, с чем это связано?

Log:
* upload completely sent off: 71 out of 71 bytes
*   Trying 178.62.211.70...
* TCP_NODELAY set
* Connected to forklog.com (178.62.211.70) port 443 (#0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: OU=Domain Control Validated; OU=PositiveSSL; CN=forklog.com
*  start date: Jan 28 00:00:00 2017 GMT
*  expire date: Jan 28 23:59:59 2019 GMT
*  subjectAltName: host "forklog.com" matched cert's "forklog.com"
*  issuer: C=GB; ST=Greater Manchester; L=Salford; O=COMODO CA Limited; CN=COMODO RSA Domain Validation Secure Server CA
*  SSL certificate verify ok.
> POST /wp-content/themes/newForklog/ajaxposts.php HTTP/1.1
Host: forklog.com
Accept: */*
https://forklog.com/news/
Content-Length: 71
Content-Type: application/x-www-form-urlencoded

* upload completely sent off: 71 out of 71 bytes
< HTTP/1.1 200 OK
< Server: nginx/1.10.3
< Date: Mon, 13 Aug 2018 14:33:29 GMT
< Content-Type: text/html; charset=UTF-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< 
* Curl_http_done: called premature == 0
* Connection #0 to host forklog.com left intact


Код:
$response = Curl::to('https://forklog.com/wp-content/themes/newForklog/ajaxposts.php')
			->withData(array(
				'action' => 'PostsByCat',
				'offset'=> 12,
				'postperpage' => 12,
				'category' => 'news/',
				'tag' => 'news/'))
			->withHeaders(array(
				'Referer' => 'https://forklog.com/news/',
				'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8',
				'X-Requested-With' => 'XMLHttpRequest',
				'Connection' => 'keep-alive'
			))->post();


Либа: https://github.com/ixudra/curl
  • Вопрос задан
  • 295 просмотров
Решения вопроса 2
Sanasol
@Sanasol Куратор тега PHP
нельзя просто так взять и загуглить ошибку
Значит не аналогично сделано...

php код показывать вы конечно не будете.

ну вот же в доке совсем по другому хедеры прописываются
https://github.com/ixudra/curl#sending-custom-headers

Не key => value
А только значения
Ответ написан
@bears
Попробуйте вот тут, получите вот такой код:
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://forklog.com/wp-content/themes/newForklog/ajaxposts.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "action=PostsByCat&offset=12&postperpage=12&category=news/&tag=news/");
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = "Referer: https://forklog.com/news/";
$headers[] = "Content-Type: application/x-www-form-urlencoded; charset=UTF-8";
$headers[] = "X-Requested-With: XMLHttpRequest";
$headers[] = "Connection: keep-alive";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);


у меня он работает прекрасно
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 1
Попробуйте User Agent поставить от браузера.
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы