【问题标题】:PHP + CURL example to post form data and receive responsePHP + CURL 示例发布表单数据并接收响应
【发布时间】:2011-02-10 16:19:11
【问题描述】:

我正在尝试使用 PHP 和 Curl 将表单数据发布到远程服务器,我还想获得服务器对发布数据的响应。

我已经编写了一个函数来使用 Curl 将数据发布到服务器。但是我想获得对 POSTed 数据的服务器响应。服务器响应将采用 JSON 格式

所以我想写一个这样的函数:

public function postFormDataAndGetResponse()
{
   // use curl to post form data (this I have already done)

   // now what Curl options to use to wait (up to a TIMEOUT interval) to receive json data from server?
}

如果有任何帮助,我将不胜感激

【问题讨论】:

  • 回滚,因为它可能对其他人有用。 (顺便说一句,您可以在 15 分钟后接受 IIRC)

标签: php json curl


【解决方案1】:

给你,简单的例子:

$ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $recived_content = curl_exec($ch); $data = json_decode($recived_content);

【讨论】:

  • 如果需要,使用 curl_getinfo($ch, CURLINFO_HTTP_CODE) 获取 http 响应代码。
  • 啊,是的,我找到了。我试图删除问题。当我被允许时,我会接受你的回答。
猜你喜欢
  • 2011-06-24
  • 2012-11-02
  • 1970-01-01
  • 1970-01-01
  • 2012-08-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-11
相关资源
最近更新 更多