2015-10-05 16 views
-1

我試圖發佈並從其他網站獲取結果,但並不總是顯示。使用cURL和PHP無法看到結果

這是後並獲取代碼:

<?php 
$data = array("categoryCode" => $_POST['CELL_PHONES_STORE'], "code" => $_POST['CELL_PHONE_IMEI_ESN'], "imeiEsn" => $_POST['imeiEsn'], "modelCode" => $_POST['APPLA1533IPHONE5S16GBATT'], "program" => $_POST['ATT']); 
$url = 'https://atttradein.flipswap.com/api/rest/v2/serialnumbers?='.$data; 
$post = curl_init(); 
curl_setopt($post, CURLOPT_URL, $url); 
curl_setopt($post, CURLOPT_RETURNTRANSFER, 1); 
$result = curl_exec($post); 
curl_close($post); 
print_r(json_decode($result)); 

?> 
+0

你確定你得到JSON編碼的數據?也許解碼調用簡單地失敗?你有沒有檢查你的http服務器錯誤日誌文件? – arkascha

+0

另外,你必須改變你打電話的方式:你寫你想打一次POST電話,但你不告訴curl這樣做。此外,你不能簡單地追加一個數組到網址,這是什麼意思給?相反,您必須將您的數據(數組)作爲捲曲選項交給它,並讓它發出發佈請求。 – arkascha

回答

1

現在我嘗試這個代碼

$data = array("categoryCode" => $_POST['CELL_PHONES_STORE'], "code" => $_POST['CELL_PHONE_IMEI_ESN'], "imeiEsn" => $_POST['imeiEsn'], "modelCode" => $_POST['APPLA1533IPHONE5S16GBATT'], "program" => $_POST['ATT'], "referer" => "https://buyback.att.com/"); 
 

 

 
//set POST variables 
 
$url = 'https://atttradein.flipswap.com/api/rest/v2/serialnumbers?='; 
 

 

 
//open connection 
 
$ch = curl_init(); 
 

 
//set the url, number of POST vars, POST data 
 
curl_setopt($ch,CURLOPT_URL, $url); 
 

 
curl_setopt ($ch, CURLOPT_POST, true); 
 
curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($data)); 
 
curl_setopt ($ch, CURLOPT_REFERER, 'https://buyback.att.com/'); 
 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
 
curl_setopt($ch, CURLOPT_STDERR, fopen('php://output', 'w+')); 
 
curl_setopt($ch, CURLOPT_VERBOSE, 1); 
 

 
//execute post 
 
$result = curl_exec($ch); 
 

 

 

 
//close connection 
 
curl_close($ch); 
 
echo $result;