【问题标题】:DELETE methods not callableDELETE 方法不可调用
【发布时间】:2014-09-07 05:06:31
【问题描述】:

由于某种原因,我似乎无法通过 Restler 调用 DELETE 方法。在我的 restler php 文件中,我定义了一个这样的方法:

    /**
     * Drop invitation
     *
     * Removes an invitation from the system.  Coaches want a way to be able
     * to remove an invite if they messed up, or the person just doesn't accept.
     *
     * @param string $email The email address of the invited person {@from body}
     * @param int $team_id The SQL identifier for the team {@from body}
     *
     * @return array An empty array
     */
    public function deleteInvite($email, $team_id) {
            return [];
    }

当我尝试调用它时:

curl -X DELETE -H "Content-Type: application/json" -d '{"email":"foo","team_id",17}' http://server.com/app/团队/邀请

返回 400 错误:

{ “错误”: { “代码”:400, "message": "错误请求:电子邮件丢失。" } }

我该怎么称呼它?

【问题讨论】:

    标签: restler


    【解决方案1】:

    作为一种被广泛接受的做法,restler 不支持/读取 GETDELETE 请求的正文参数。将它们发送到 url 或作为查询字符串发送。

    正如您在https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-p2-semantics-26#section-4.3 中看到的那样

    • HEAD - 没有定义的正文语义。
    • GET - 没有定义的正文语义。
    • PUT - 支持正文。
    • POST - 支持正文。
    • DELETE - 没有定义的正文语义。
    • TRACE - 正文支持。
    • OPTIONS - 支持正文,但没有语义(可能在未来)。

    许多 http 服务器不解析 GETDELETE 请求的正文,restler 正在遵循这种做法

    【讨论】:

    • 谢谢。为什么这是“最佳实践”?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-21
    • 1970-01-01
    • 2019-07-07
    • 1970-01-01
    • 2015-02-08
    相关资源
    最近更新 更多