好的,所以在我的网络应用程序的 API 中,我有一个传入的 HTTP 发布请求。 我想将该 POST 请求传递到另一台服务器,而不会丢失 POST header 中的数据。这可能吗?我会使用哪种类型的重定向? php 例子?
编辑:HTTP 请求来自移动应用,而不是网络浏览器。
谢谢!
最佳答案
您可以使用 cURL 或套接字重新发布数据,但您不能真正重定向它。
使用 cURL 发布到 URL:
$ch = curl_init('http://www.somewhere.com/that/receives/postdata.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($_POST));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
关于php - 重定向 HTTP POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4939195/