2015-10-28 49 views
0

以下是我的App Engine端點。我將它註釋爲ApiMethod.HttpMethod.GET,因爲我希望能夠通過瀏覽器進行get調用。這個類本身有幾十種可以理解的方法。其中一些使用POST。但getItems註明GET。當我嘗試通過瀏覽器調用的URL,我得到一個405錯誤App Engine端點:此URL不支持HTTP方法GET

Error: HTTP method GET is not supported by this URL 

代碼:

@Api(name = "myserver",
 
     namespace = @ApiNamespace(ownerDomain = "thecompany.com", ownerName = "thecompany", packagePath = ""),
 
     version = "1", description = "thecompany myserver", defaultVersion = AnnotationBoolean.TRUE 

) 公共類MYSERVER {

@ApiMethod(name = "getItems", httpMethod = ApiMethod.HttpMethod.GET)
 
public CollectionResponse<Item> getItems(@Named("paramId") Long paramId) {
  
    …
  
    return CollectionResponse.<Item>builder().setItems(ItemList).build();
  
} 

} 

這不是本地主機,它是爲真正的服務器。也許我錯誤地形成了網址。我曾嘗試過幾個網址,例如

https://thecompanymyserver.appspot.com/_ah/spi/com.thecompany.myserver.endpoint.myserver.getItems/v1/paramId=542246400 

https://thecompanymyserver.appspot.com/_ah/spi/myserver/NewsForVideo/v1/542246400 
+0

爲什麼現在格式化SO代碼非常困難?它曾經很容易。他們曾經「修復」他們需要將它改回來。 – learner

+1

您可以使用api資源管理器找出您是否使用了正確的網址。轉到https://yourprojectid.appspot.com/_ah/api/explorer。另外,如果您不打算使用google javascript api客戶端,則應該在'@ ApiMethods'中添加'path = ...',這樣您就可以確定實際的路徑。 – konqi

回答

0

您可以使用api資源管理器找出您是否使用了正確的網址。轉到

https://yourprojectid.appspot.com/_ah/api/explorer 

這部作品在devserver還有:

http://localhost:8080/_ah/api/explorer 

此外,如果你不打算使用谷歌的JavaScript API客戶端,您應該添加path="..."@ApiMethod S,所以你確定實際路徑是什麼。

+0

api資源管理器不提供任何細節。它顯示我的服務器的名稱,但是當我點擊它時什麼也沒有發生:不擴展,沒有任何事情發生。 – learner

+0

@learner今天的API瀏覽器看起來確實有點破。嘗試以下操作:轉至「/_ah/api/explorer'。點擊API,如果沒有任何反應,URL應該是正確的,因此請點擊URL並按Enter鍵。它現在應該列出您的端點方法。選擇一個並按下'Execute',你應該看到正確的端點URL。 – konqi

1

正確的路徑是/_ah/api/myserver/1/getItems。/_ah/spi是指後端路徑,它只接受不同格式的POST請求。

備註:API版本是典型的「vX」而不是「X」。

+0

所有這些都失敗了:'https://myprojectid.appspot.com/_ah/api/myserver/1/getItems/?itemid = 234561778737373333'和 'https://myprojectid.appspot.com/_ah/ api/myserver/1/getItems/234561778737373333'和 'https:// myprojectid.appspot.com/_ah/api/myserver/1/getItems/itemid/234561778737373333' – learner

+0

您應該可以使用API​​資源管理器一個測試請求,它會顯示你需要的URL。不過,嘗試從第一個網址中刪除結尾的斜槓。將有助於知道你現在得到什麼錯誤。不應該是405。 – saiyr

相關問題