【发布时间】:2016-05-12 18:56:59
【问题描述】:
我正在尝试使用 Endpoints 在 App Engine 上运行 cronjob。
我在使用 cronjob 时收到 Method Not Allowed (HTTP 405) 错误。如何解决此错误?
这是我目前的cron.xml:
<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/_ah/spi/messaging/v1/checkUpdates</url>
<description>Check for news every 5 minutes</description>
<schedule>every 5 minutes</schedule>
</cron>
<cron>
<url>/_ah/spi/package.backend.MessagingEndpoint.checkUpdates</url>
<description>Check for news every 5 minutes</description>
<schedule>every 5 minutes</schedule>
</cron>
</cronentries>
没有代码主体的我的端点:
@ApiMethod(
name = "checkUpdatesPost",
httpMethod = ApiMethod.HttpMethod.POST
)
public void checkUpdatesPost() {
checkUpdates();
}
@ApiMethod(
name = "checkUpdates",
httpMethod = ApiMethod.HttpMethod.GET
)
public void checkUpdates() {
// ... Stuff
}
通过Google APIs Explorer 运行这些函数中的任何一个都可以正常运行:
使用GET进行测试
GET https://myapp.appspot.com/_ah/api/messaging/v1/checkUpdates
使用POST进行测试
POST https://myapp.appspot.com/_ah/api/messaging/v1/checkUpdatesPost
这是日志,在Logs Viewer 上看到:
您可以在这里看到AppEngine-. 指的是 Cron 的尝试。 Chrome 48 是我的浏览器/Google APIs Explorer 的尝试。
据我了解,Cron 不与POST 一起使用。为此,我为GET 创建了另一个函数,它反映了POST 的函数。
在我的cron.xml 中,我提供了两种变体。
-
/_ah/spi/messaging/v1/checkUpdates- 这是我在浏览器中用来访问资源的内容。 -
/_ah/spi/package.backend.MessagingEndpoint.checkUpdates- 这是我在浏览器中运行 #1 后在日志查看器中看到的内容。
【问题讨论】:
标签: google-app-engine cron google-cloud-endpoints