有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

JavaGoogleAppEngine推送任务始终返回405

我在Google App Engine上实现了一个推送任务队列。这是我如何调用任务队列的代码

 Queue queue = QueueFactory.getDefaultQueue();
 queue.add(TaskOptions.Builder.withUrl("/tasks/myTask").param("myparam", Long.toString(myparam)).retryOptions(RetryOptions.Builder.withTaskRetryLimit(1)).method(TaskOptions.Method.POST)) ;

这是任务的代码

 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);

        String param = req.getParameter("myparam") ;

        resp.setStatus(HttpServletResponse.SC_OK);

        resp.setContentType("text/plain");
        resp.getWriter().println("dummy");
        resp.getWriter().flush();
    }

但我可以在日志中看到,我的任务返回状态代码405,任务将再次执行,但在我的代码中,我将值200设置为响应代码。知道我的代码为什么不起作用吗


共 (1) 个答案

  1. # 1 楼答案

    医生说

    TaskOptions.Builder constructor has methods to add data as the payload of the HTTP request, and as parameters, which are added to the URL as query parameters.

    Params

    Do not specify params if you are using the POST method along with a payload, or if you are using the GET method and you've included a url with query parameters.

    您正在使用POST方法添加任务

    删除对.method(TaskOptions.Method.POST)的调用