PHP+;提交表单数据并接收响应的CURL示例
我试图使用PHP和Curl将表单数据发布到远程服务器,我还想获得服务器对发布数据的响应 我已经编写了一个函数,使用Curl将数据发布到服务器。然而,我想得到服务器对发布数据的响应。服务器响应将使用JSON格式 所以我想写一个这样的函数:PHP+;提交表单数据并接收响应的CURL示例,php,json,curl,Php,Json,Curl,我试图使用PHP和Curl将表单数据发布到远程服务器,我还想获得服务器对发布数据的响应 我已经编写了一个函数,使用Curl将数据发布到服务器。然而,我想得到服务器对发布数据的响应。服务器响应将使用JSON格式 所以我想写一个这样的函数: public function postFormDataAndGetResponse() { // use curl to post form data (this I have already done) // now what Curl opt
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?
}
如果有任何帮助,我将不胜感激。给你,简单的例子: $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $recived_content = curl_exec($ch); $data = json_decode($recived_content); $ch=curl\u init($url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); $received\u content=curl\u exec($ch); $data=json_decode($received_content);
如果需要,可以使用curl\u getinfo($ch,CURLINFO\u HTTP\u代码)获取HTTP响应代码。啊,是的,我找到了。我试图删除这个问题。当我被允许时,我会接受你的回答。回退,因为这可能对其他人有用。(顺便说一句,15分钟后您可以接受IIRC)