2014-05-25 38 views
0

我試圖使用ZF1其餘客戶與Zend_Rest_Client

$this->restClient = new Zend_Rest_Client('https://myurl.com'); 
$response = $this->restClient->delete('/service/'.$this->uuid.'.json?api_key='.$this->apikey); 

刪除資源刪除,但我得到一個錯誤:

Path "/service/v-2149d050-c64b-0131-33b0-1231390c0c78.json?api_key=a-9a136a00-b340-0131-2662-1231390c0c78" is not a valid HTTP path 

網絡服務文檔簡單的說就是用

DELETE https://myurl.com/service/YOUR_UUID.json?api_key=YOUR_API_KEY 

關於如何使用這個類的任何想法?

感謝

+0

「'?'」是HTTP URI中的保留字符,如果要在URI的路徑中使用它,則需要對其進行百分比編碼。在你的代碼中你有*沒有*編碼它。 – hakre

回答

0
DELETE https://myurl.com/service/YOUR_UUID.json?api_key=YOUR_API_KEY 

也就是說只有路徑,而是一個完整的URI。它分解爲:

  • 路徑:service/YOUR_UUID.json
  • 查詢的信息:api_key=YOUR_API_KEY

對於Zend的REST客戶端,你需要調用每個每個參數的一個功能,參數不能被命名作爲一個標準的HTTP動詞:

$client = new Zend_Rest_Client('https://exeample.com'); 
$client->api_key(YOUR_API_KEY); 

$response = $client->restClient->delete('/service/'.$this->uuid.'.json); 

欲瞭解更多信息,請參閱如何傳遞參數符合你的要求the Request Arguments section in the vendor documentation

+0

也看到:http://stackoverflow.com/q/4725471/367456 – hakre

+0

我試過這種方式,但我得到這個: 錯誤:simplexml_load_string():^ – user3174311

+0

@ user3174311:恭喜,你已經解決了沒有得到* 「路徑XXX不是有效的HTTP路徑」*錯誤不再。那正是你問到的,不是嗎? – hakre