2015-10-28 48 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

相关问题