2015-12-02 95 views
0

我有一個pHP捲曲調用嘗試做並已經得到它的工作;我有它,所以調用的輸出是使用「返回傳輸:真」放入數組;但是當我這樣做時,API(200,300,400等)的響應代碼不在輸出的數組中;所以我想知道我怎麼可以得到響應代碼也倒入一個變量以備後用...這裏是我的代碼:需要獲取API響應代碼到變量的幫助

$data = array(
'username' => $username, 
'password' => $password, 
); 



$data = http_build_query($data); // convert array to urlencoded string 

$curl = curl_init(); 
curl_setopt_array($curl, array(
CURLOPT_URL => 'http://myapiaddress', //URL to the API 
CURLOPT_POST => true, 
CURLOPT_POSTFIELDS => $json, 
CURLOPT_HEADER => true, 
CURLOPT_HTTPHEADER => array('Content-Type: application/x-www-form- urlencoded','Accept: application/json',$token_string) 

)); 

curl_setopt($curl, CURLOPT_POSTFIELDS, $data); 

curl_setopt($curl,CURLOPT_RETURNTRANSFER,TRUE); 

$resp = curl_exec($curl); 
curl_close($curl); 

太感謝了,傑拉德

回答