Mimicking an ajax call with Curl PHP

前端 未结 1 1807
-上瘾入骨i
-上瘾入骨i 2020-12-16 17:18

I\'m scraping a site using curl (via PHP) and some information I want is a list of products which is by default only showing the first few ones. The rest is passed to the us

相关标签:
1条回答
  • 2020-12-16 17:38

    To set the request verification token as a header, more closely mimic an AJAX request, and set the content-type to JSON, use CURLOPT_HEADER.

    curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Requested-With: XMLHttpRequest", "Content-Type: application/json; charset=utf-8", "__RequestVerificationToken: $token"));
    

    I also notice that you're superfluously setting CURLOPT_POST to false on line 7 of your code, and that the post data you're sending isn't in JSON format. You should have:

    $postVariables = '{"historyPageIndex":1,"displayPeriod":0,"productsType":"All"}';
    
    0 讨论(0)
提交回复
热议问题