如何使用 PHP 转发/重定向 HTTP PUT 请求?
我在服务器上收到 HTTP PUT 请求,我想将这些请求重定向/转发到其他服务器。
我使用 PHP 在两台服务器上处理 PUT 请求。
PUT 请求使用基本 HTTP 身份验证。
下面是一个示例:
www.myserver.com/service/put/myfile.xml
重定向到
www.myotherserver.com/service/put/myfile.xml
如何在不将文件保存在第一台服务器上并使用 CURL 重新发送 PUT 请求的情况下执行此操作?
谢谢!
I receive HTTP PUT requests on a server and I would like to redirect / forward these requests to an other server.
I handle the PUT request on both server with PHP.
The PUT request is using basic HTTP authentication.
Here is an example :
www.myserver.com/service/put/myfile.xml
redirect to
www.myotherserver.com/service/put/myfile.xml
How can I do this without saving the file on my first server and resending a PUT request using CURL?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
HTTP/1.1 为此类重定向定义了状态代码 307。然而,PUT 通常由客户端软件使用,您几乎可以假设没有人支持 307。
执行此操作的最有效方法是在 Apache 上设置代理以将请求重定向到新 URL。
这就是你如何在 PHP 中代理它,
HTTP/1.1 defines status code 307 for such redirect. However, PUT is normally used by client software and you can pretty much assume no one honors 307.
The most efficient way to do this is to setup a proxy on Apache to redirect the request to the new URL.
This is how you can proxy it in PHP,
不可能。重定向隐式是一个
GET
请求。您需要使用curl
来玩代理。从技术上讲,也没有必要保存在磁盘上,您可以将响应主体直接通过管道传输到 Curl 的请求主体。但由于我从未在 PHP 中这样做过(在 Java 中这是小菜一碟),所以我无法对此给出更详细的答案。
Not possible. A redirect is implicitly a
GET
request. You'll need to have to play for a proxy usingcurl
.Saving on disk is technically also not necessary, you could just pipe the reponse body directly to the request body of Curl. But since I've never done this in PHP (in Java it's a piece of cake), I can't give a more detailed answer about that.