我需要在用户进行 POST 后将用户重定向到另一个端点,但另一个端点只接受 GET 请求。
正如 wiki 所说,HTTP 代码 303 应该告诉客户端将请求发送到另一个位置并将方法更改为 GET:
如果服务器使用 303 See Other 响应和 location 标头的值响应 POST 或其他非幂等请求,则客户端应使用 GET 方法(source)获取 location 标头中提到的资源。
但是在响应之后,客户端再次使用 POST 重定向。我用 Insomnia 测试了端点,这是时间线输出:
* Preparing request to http://******:8080/ords/demo/llmob.test_post_david
* Current time is 2020-09-10T07:21:09.418Z
* Using libcurl/7.69.1 OpenSSL/1.1.1e zlib/1.2.11 brotli/1.0.7 libidn2/2.2.0 libssh2/1.9.0 nghttp2/1.29.0
* Using default HTTP version
* Disable timeout
* Enable automatic URL encoding
* Enable SSL validation
* Enable cookie sending with jar of 5 cookies
* Connection 21 seems to be dead!
* Closing connection 21
* Hostname ****** was found in DNS cache
* Trying 192.168.254.135:8080...
* Connected to ****** (192.168.254.135) port 8080 (#22)
> POST /ords/demo/llmob.test_post_david HTTP/1.1
> Host: ******:8080
> User-Agent: insomnia/2020.3.3
> Access-Control-Allow-Origin: *
> Content-Type: multipart/form-data; boundary=X-INSOMNIA-BOUNDARY
> Accept: */*
> Content-Length: 433
| --X-INSOMNIA-BOUNDARY
| Content-Disposition: form-data; name="ShoppingCartID"
| 78
* We are completely uploaded and fine
* Mark bundle as not supporting multiuse
< HTTP/1.1 303
< Location: http://******:8080/ords/devapex/sbas/r/self-check-out159/odobreno
< Transfer-Encoding: chunked
< Date: Thu, 10 Sep 2020 07:21:10 GMT
* Ignoring the response-body
* Received 5 B chunk
* Connection #22 to host ****** left intact
* Issue another request to this URL: 'http://******:8080/ords/devapex/sbas/r/self-check-out159/odobreno'
* Disables POST, goes with GET
* Found bundle for host ******: 0x1497368c8870 [serially]
* Can not multiplex, even if we wanted to!
* Re-using existing connection! (#22) with host ******
* Connected to ****** (192.168.254.135) port 8080 (#22)
> POST /ords/devapex/sbas/r/self-check-out159/odobreno HTTP/1.1
> Host: ******:8080
> User-Agent: insomnia/2020.3.3
> Access-Control-Allow-Origin: *
> Content-Type: multipart/form-data; boundary=X-INSOMNIA-BOUNDARY
> Accept: */*
> Content-Length: 433
| --X-INSOMNIA-BOUNDARY
| Content-Disposition: form-data; name="ShoppingCartID"
| 78
* We are completely uploaded and fine
* Mark bundle as not supporting multiuse
< HTTP/1.1 405
< Allow: GET
< Content-Type: text/html
< Content-Length: 15798
< Date: Thu, 10 Sep 2020 07:21:10 GMT
* Received 7.9 KB chunk
* Received 7.5 KB chunk
* Connection #22 to host ****** left intact
第一个响应是使用OWA_UTIL
包生成的,如下所示:
owa_util.status_line(
nstatus=> 303, bclose_header=> false
);
owa_util.redirect_url(
curl => 'http://******:8080/ords/devapex/sbas/r/self-check-out159/odobreno',
bclose_header =>TRUE
);
ORDS 版本 18.4。
更新
当从浏览器发出相同的请求时,响应代码为 403(以下错误),并且永远不会发生重定向。
无法处理该请求,因为该资源不支持跨域共享请求,或者请求 Origin 无权访问该资源。如果 ords 正在被反向代理,请确保前端服务器正在传播主机名,对于 mod_proxy,请确保 ProxyPreserveHost 设置为 On