Помогите с POST запросом плиз

D
На сайте с 28.06.2008
Offline
1103
264

Задача вытащить товары с этой страницы https://www.yogaoutlet.com/collections/aura-cacia  они подгружаются через  JSON

Если в хром посмотреть запрос и скопировать его получается это

fetch("https://so803w35w2-dsn.algolia.net/1/indexes/*/queries?x-algolia-agent=Algolia%20for%20JavaScript%20(3.33.0)%3B%20Browser&x-algolia-application-id=SO803W35W2&x-algolia-api-key=b1c6e8be7d8cc15ed3229cdc5c945a1b", {
  "headers": {
    "accept": "application/json",
    "accept-language": "ru,en;q=0.9,ba;q=0.8,it;q=0.7,pt;q=0.6,de;q=0.5,uk;q=0.4,cy;q=0.3,mt;q=0.2,sr;q=0.1,bg;q=0.1",
    "cache-control": "no-cache",
    "content-type": "application/x-www-form-urlencoded",
    "pragma": "no-cache",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "cross-site"
  },
  "referrer": "https://www.yogaoutlet.com/collections/aura-cacia",
  "referrerPolicy": "no-referrer-when-downgrade",
  "body": "{\"requests\":[{\"indexName\":\"YO-Shopify Sort: Most Popular\",\"params\":\"query=&page=0&hitsPerPage=48&clickAnalytics=true&attributesToHighlight=%5B%22%22%5D&facets=%5B%22catls%22%2C%22manufacturer%22%2C%22isnew%22%2C%22issale%22%2C%22IsBestSeller%22%2C%22IsHotDeal%22%2C%22SizeList%22%2C%22ColorList%22%2C%22PriceRangeText%22%2C%22PercentOffRanges%22%2C%22Att_Material%22%2C%22Att_Pattern%22%2C%22Att_Durability%22%2C%22Att_YogaPractice%22%2C%22Att_Thickness%22%2C%22Att_MatWeight%22%2C%22Att_MatStructure%22%2C%22Att_MatSize%22%2C%22ShopifyCustomCollections%22%5D&maxValuesPerFacet=300&facetFilters=%5B%22ManufacturerID%3A87603544099%22%5D&numericFilters=%5B%5D\"}]}",
  "method": "POST",
  "mode": "cors",
  "credentials": "omit"
});

Далее я в CURL прописываю

    curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    "accept" => "application/json",
    "accept-language"=> "ru,en;q=0.9,ba;q=0.8,it;q=0.7,pt;q=0.6,de;q=0.5,uk;q=0.4,cy;q=0.3,mt;q=0.2,sr;q=0.1,bg;q=0.1",
    "cache-control"=> "no-cache",
    "content-type"=> "application/x-www-form-urlencoded",
    "pragma"=> "no-cache",
    "sec-fetch-dest"=> "empty",
    "sec-fetch-mode"=> "cors",
    "sec-fetch-site"=> "cross-site"
  ));

и в строку  

curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);

передаю массив

    $post_data = [
        "requests"=>[
            "indexName"=>"YO-Shopify Sort: Most Popular",
            "params"=>"query=&page=0&hitsPerPage=48&clickAnalytics=true&attributesToHighlight=%5B%22%22%5D&facets=%5B%22catls%22%2C%22manufacturer%22%2C%22isnew%22%2C%22issale%22%2C%22IsBestSeller%22%2C%22IsHotDeal%22%2C%22SizeList%22%2C%22ColorList%22%2C%22PriceRangeText%22%2C%22PercentOffRanges%22%2C%22Att_Material%22%2C%22Att_Pattern%22%2C%22Att_Durability%22%2C%22Att_YogaPractice%22%2C%22Att_Thickness%22%2C%22Att_MatWeight%22%2C%22Att_MatStructure%22%2C%22Att_MatSize%22%2C%22ShopifyCustomCollections%22%5D&maxValuesPerFacet=300&facetFilters=%5B%22ManufacturerID%3A87603544099%22%5D&numericFilters=%5B%5D"]];
   

Но что-то не проходит запрос зараза, где ошибаюсь?

Получаю ответ

 ["textContent"]=>
      string(142) "{"message":"lexical error: malformed number, a digit is required after the minus sign. Around '----------' near line:1 column:1","status":400}"


D
На сайте с 28.06.2008
Offline
1103
#1

Вроде топик создавал в теме "Веб строительство", как он тут оказался непонятно.

Проблему решил передав не массивом а строкой параметры.

N
На сайте с 10.12.2012
Offline
81
#2
А так?
$post_data = json_encode([
        "requests"=>[
            "indexName"=>"YO-Shopify Sort: Most Popular",
            "params"=>"query=&page=0&hitsPerPage=48&clickAnalytics=true&attributesToHighlight=%5B%22%22%5D&facets=%5B%22catls%22%2C%22manufacturer%22%2C%22isnew%22%2C%22issale%22%2C%22IsBestSeller%22%2C%22IsHotDeal%22%2C%22SizeList%22%2C%22ColorList%22%2C%22PriceRangeText%22%2C%22PercentOffRanges%22%2C%22Att_Material%22%2C%22Att_Pattern%22%2C%22Att_Durability%22%2C%22Att_YogaPractice%22%2C%22Att_Thickness%22%2C%22Att_MatWeight%22%2C%22Att_MatStructure%22%2C%22Att_MatSize%22%2C%22ShopifyCustomCollections%22%5D&maxValuesPerFacet=300&facetFilters=%5B%22ManufacturerID%3A87603544099%22%5D&numericFilters=%5B%5D"]]);


S3
На сайте с 29.03.2012
Offline
307
#3
Dram #:
Проблему решил передав не массивом а строкой параметры.

Потому что вытягиваются данные GET - запросом  а не  POST

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий