我正在創建http_client對象併發出GET請求。以下是我的代碼。雖然從JSON中提取身體部分時出錯php
$httpc = new HTTP_CLIENT();
$httpc->get("$endpointUrl?operation=getchallenge&username=$userName");
$response = $httpc->currentResponse();
print_r($response);
output: Array ([url] => http://localhost:8888//webservice.php?operation=getchallenge&username=admin [code] => 200 [headers] => Array ([date] => Thu, 27 Sep 2012 07:30:17 GMT [server] => Apache/2.0.52 (Win32) PHP/5.2.6 [x-powered-by] => PHP/5.2.6 [expires] => Thu, 19 Nov 1981 08:52:00 GMT [cache-control] => no-store, no-cache, must-revalidate, post-check=0, pre-check=0 [pragma] => no-cache [content-length] => 102 [connection] => close [content-type] => application/json) [body] => {"success":true,"result":{"token":"50640089780c4","serverTime":1348731017,"expireTime":1348731317}})
jsonResponse = Zend_JSON::decode($response['body']);
我試圖從這個數組中提取「body」部分,但是我得到的值是空的。如果可以,請幫助我。
注意:您可以在[body]部分開始處看到輸出具有JUNK值。
'$ endpointUrl'是你的腳本或API? –
@MihaiIorga,我正在使用API –