2016-06-11 98 views
1

試圖測試Uber Rush API(從本地主機和從Linux服務器)。Uber Rush API Sandbox

呼叫標記的工作 - 我得到的令牌 試圖實現的SANbox例如:

curl -X "PUT /v1/sandbox/deliveries/{delivery_id}" \ 
    -H "Authorization: Bearer <OAUTH TOKEN>" \ 
    -d "{\"status\":\"en_route_to_pickup\"}" 

與URL https://sandbox-api.uber.com/

,我試着用的file_get_contents(在PHP)

所以相同的請求,我總是得到錯誤「405方法不允許」

{"message":"Method not supported for this endpoint.","code":"method_not_allowed"} 

我需要做什麼才能從此沙盒示例https://developer.uber.com/docs/rush/sandbox訪問方法?

Corrent語法

curl -X "PUT" -H "Authorization: Bearer <TOKEN>" -H "Content-Type: application/json" -d "{\"status\":\"en_route_to_pickup\"}" https://sandbox-api.uber.com/v1/sandbox/deliveries/DELIVERY_ID 
+0

你正在做什麼確切的調用file_get_contents? –

+0

'$ url ='https://sandbox-api.uber.com/v1/sandbox/deliveries/ID_HERE'; $ headers = array('Authorization:Bearer'.TOKEN_HERE); $ options = array( 'https'=> array( 'header'=> $ headers, ), ); $ context = stream_context_create($ options); $ result = file_get_contents($ url,false,$ context);' –

回答

0

編輯:更新你的問題,以反映這兩個問題...

您的要求不匹配和捲曲的不正確的語法。

首先您的CURL請求被錯誤地指定。它應該是:

curl -X "PUT" -H "Authorization: Bearer <OAUTH TOKEN>" -d "{\"status\":\"en_route_to_pickup\"}" https://sandbox-api.uber.com/v1/sandbox/deliveries/{delivery_id} 

此外,您的curl命令試圖發出PUT請求uber sandbox PUT API。但是,您的PHP代碼不能正確設置上下文,因此可能會發出GET請求。因此,我懷疑服務器因爲不允許進行這種操作而將請求拒絕爲GET。請參閱Bad request using file_get_contents for PUT request in PHP。這應該給你一個例子,說明如何通過必要的上下文來使用file_get_contents()來發出PUT請求。

+0

爲了乾淨,我使用了所有可能的選項來使這個請求有效。這也與方法PUT一樣。 $ url ='https://sandbox-api.uber.com/v1/sandbox/deliveries/ID_HERE'; $ headers = array('Authorization:Bearer'.TOKEN_HERE); $選項=陣列( 的 'https'=>數組( '標題'=> $標頭, '方法'=> 'PUT', ) ); $ context = stream_context_create($ options); $ result = file_get_contents($ url,false,$ context); –

+0

我不擔心php代碼,我擔心爲什麼我不能在curl命令上使用方法。我在這裏得到這個代碼[https://developer.uber.com/docs/rush/sandbox](https://developer.uber.com/docs/rush/sandbox) –

+0

@ЕвгенийИванов如果你的問題是curl請求,這只是因爲它在語法上不正確。看到我編輯的答案... –