POST 来自 REST 控制台,被服务器视为 GET
POST from REST console perceived as GET by server
我正在使用 chrome REST API 控制台和 Postman 向我的服务器(运行 nginx 和 symfony2)发送 post 请求
这是一个非常简单的请求,只是简单地 posting 到一个空主体的 URL。如果此请求通过 HTTP 请求从另一台服务器运行,它将注册为 POST。尝试从 api 控制台 POST 在我的 nginx 访问日志中注册为 GET 并且 returns 不允许使用 405 方法。
如果我使用 curl,我最初得到一个 301 永久移动,所以我必须使用 -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
如果仔细观察,您会看到您的请求是通过 HTTP 发出的。然后您的服务器将重定向发送到您的 HTTPS 站点。并且 301 重定向不保留请求方法。您必须针对 HTTPS 正确发出所有请求。
我正在使用 chrome REST API 控制台和 Postman 向我的服务器(运行 nginx 和 symfony2)发送 post 请求
这是一个非常简单的请求,只是简单地 posting 到一个空主体的 URL。如果此请求通过 HTTP 请求从另一台服务器运行,它将注册为 POST。尝试从 api 控制台 POST 在我的 nginx 访问日志中注册为 GET 并且 returns 不允许使用 405 方法。
如果我使用 curl,我最初得到一个 301 永久移动,所以我必须使用 -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
如果仔细观察,您会看到您的请求是通过 HTTP 发出的。然后您的服务器将重定向发送到您的 HTTPS 站点。并且 301 重定向不保留请求方法。您必须针对 HTTPS 正确发出所有请求。