【问题标题】:PHP HTTP Post from server rather than from client来自服务器而不是来自客户端的 PHP HTTP Post
【发布时间】:2013-07-04 03:18:22
【问题描述】:

目前,我的脚本需要来自用户的输入,然后用户将执行 HTTP Post(使用 curl),响应将是另一个下载文件的 url,当用户点击它时,会触发将文件下载到用户的电脑中。

现在一切正常,但我需要将流程更改为:

  1. 用户输入后,http post 必须来自服务器,而不是来自用户的机器。
  2. 随后的文件下载也将进入服务器并随后显示给用户。

对于 2) 我正在使用以下PHP download to server instead of client

对于 1),如何在用户输入后从服务器而不是客户端进行 http 发布?

【问题讨论】:

标签: php


【解决方案1】:

您可以使用 Curl 库从您的服务器执行 POST 操作。试试这个 -

$url = "http://www.example.com/submit.php";
$fields = "field1=" . $value1 . "&field2=" . $value2;
$conn = curl_init();
curl_setopt($conn, CURLOPT_URL, $url);
curl_setopt($conn, CURLOPT_POST, 2);
curl_setopt($conn, CURLOPT_POSTFIELDS, $fields);
$result = curl_exec($conn);
curl_close($conn);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-12
    • 1970-01-01
    • 2017-06-18
    • 1970-01-01
    相关资源
    最近更新 更多