2015-10-03 59 views
-1

如何在標頭中發送curl請求。請檢查此請求並讓我知道如何實現此curl url並獲取產品詳細信息。snapdeal將curl請求發送到PHP中的標頭

curl -H "Snapdeal-Affiliate-Id:aaaaa" -H "Snapdeal-Token-Id:bbbbb" "affiliate-feeds.snapdeal.com/feed/api/category/v1:586:1461823?expiresAt=1441751400001&signature=cvtwgjgrrbozmumlaalg" -H "Accept:application/json" 
+0

你的意思是如何在一個捲曲的請求發送一個頭?如果是這樣,請參閱[http://stackoverflow.com/questions/356705/how-to-send-a-header-using-a-http-request-through-a-curl-call](http://stackoverflow。 COM /問題/ 356705 /如何 - 發送 - 一個頭,使用-A-HTTP請求,通過-A-捲曲呼叫) –

回答

0

這是你將如何實現它在純PHP($響應snapdeal的JSON響應,那麼):

<?php 

/** 
* curl -H "Snapdeal-Affiliate-Id:aaaaa" -H "Snapdeal-Token-Id:bbbbb" 
* "affiliate-feeds.snapdeal.com/feed/api/category/v1:586:1461823?expiresAt=1441751400001&signature=cvtwgjgrrbozmumlaalg" -H "Accept:application/json" 
*/ 

$ch = curl_init(); 

curl_setopt($ch, CURLOPT_URL, "affiliate-feeds.snapdeal.com/feed/api/category/v1:586:1461823?expiresAt=1441751400001&signature=cvtwgjgrrbozmumlaalg"); 
curl_setopt(
    $ch, CURLOPT_HTTPHEADER, 
    array(
     'Snapdeal-Affiliate-Id:aaaaa', 
     'Snapdeal-Token-Id:bbbbb', 
     'Accept:application/json' 
    ) 
); 

$response = curl_exec($ch); 
curl_close($ch); 

// work with $response here: 
$data = json_decode($response);