0
我通常使用curl調用REST API的這樣需要實現Zend_Rest_Client以下捲曲方法
$user_data = array("userName" => "[email protected]" ,"password" => "mydomain123");
$data = json_encode($user_data);
$headers = array('Accept: application/json', 'Content-Type: application/json',);
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, 'http://myursl.com/myapi/v1/Api.svc/something/someother');
curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($handle);
$code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
curl_close($handle);
print_r($response);
上面的代碼工作正常使用API和打印預期的響應,當我用做同樣的事情Zend框架的Zend_Rest_client
這樣
$base_url = 'http://myursl.com/myapi/v1_0/Api.svc';
$endpoint = '/something/someother';
$user_data = array("userName" => "[email protected]" ,"password" => "mydomain123");
$client = new Zend_Rest_Client($base_url);
$response = $client->restPost($endpoint, $user_data);
我收到404錯誤這樣
(Zend_Http_Response)#62 (5) { ["version":protected]=> string(3) "1.1" ["code":protected]=> int(404) ["message":protected]=> string(9) "Not Found"] }
在哪裏其實我錯了,在實施的Zend REST客戶端提前
感謝您迴應這篇文章
Zend_Rest已被棄用,並將在ZF2中被移除以支持Zend \ Http。你可以嘗試用Zend_Http做同樣的事情嗎? – Maks3w
我現在無法將我的web應用程序升級到ZF2,它已在ZF1.10中完成。請在ZF 1.10中建議任何解決方案 –
我建議您不要在棄用的組件上構建新的東西。然而,你的base_url不同於CURL Zend_Rest – Maks3w