【问题标题】:POST from REST console perceived as GET by server来自 REST 控制台的 POST 被服务器视为 GET
【发布时间】:2015-09-15 08:40:29
【问题描述】:

我同时使用 chrome REST API 控制台和 Postman 向我的服务器发送一个 post 请求(运行 nginx 和 symfony2)

这是一个非常简单的请求,只是简单地发布到一个带有空正文的 URL。如果此请求通过 HTTP 请求从另一台服务器运行,它将注册为 POST。尝试从 api 控制台进行 POST 在我的 nginx 访问日志中注册为 GET 并返回 405 Method not allowed。

如果我使用 curl,我最初会得到 301 Moved Permanently,所以我必须使用 -L 来跟踪重定向。我不确定这是否是标准 Symfony 或者它是否正在影响请求。

我发现 curl 请求存在一些问题,但不确定如何解决。

$ curl -v -L -d "1EepG1a63X" xxx.io/api/convert_mov/
*   Trying xx.76.9.82...
* Connected to xxx.io (xx.76.9.82) port 80 (#0)
> POST /api/convert_mov/ HTTP/1.1
> Host: xxx.io
> User-Agent: curl/7.43.0
> Accept: */*
> Content-Length: 10
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 10 out of 10 bytes
< HTTP/1.1 301 Moved Permanently
< Server: nginx/1.6.2
< Date: Tue, 15 Sep 2015 09:00:43 GMT
< Content-Type: text/html
< Content-Length: 184
< Connection: keep-alive
< Location: https://xxx.io/api/convert_mov/
<
* Ignoring the response-body
* Connection #0 to host xxx.io left intact
* Issue another request to this URL: 'https://xxx.io/api/convert_mov/'
* Switch from POST to GET
* Found bundle for host xxx.io: 0x7fcad9c14e70
*   Trying xx.76.9.82...
* Connected to xxx.io (xx.76.9.82) port 443 (#1)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
* Server certificate: xxx.io
* Server certificate: DigiCert SHA2 Secure Server CA
* Server certificate: DigiCert Global Root CA
> GET /api/convert_mov/ HTTP/1.1
> Host: xxx.io
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Server: nginx/1.6.2
< Content-Type: text/html; charset=UTF-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< X-Powered-By: PHP/5.5.25
< Cache-Control: no-cache
< Date: Tue, 15 Sep 2015 09:00:43 GMT

【问题讨论】:

    标签: symfony nginx


    【解决方案1】:

    如果您仔细观察,您会发现您的请求是通过 HTTP 进行的。然后您的服务器将重定向发送到您的 HTTPS 站点。并且 301 重定向不保留请求方法。您必须针对 HTTPS 正确发出所有请求。

    【讨论】:

    • 有趣,我认为,至少在协议方面,原始的method 会被保留。有用的信息...
    • 哈哈,IE 确实让我们的生活更有趣 :D
    猜你喜欢
    • 2013-10-03
    • 1970-01-01
    • 1970-01-01
    • 2013-04-09
    • 1970-01-01
    • 2012-04-07
    • 1970-01-01
    • 2012-10-31
    • 1970-01-01
    相关资源
    最近更新 更多