cURL操作与PHP

cURL操作与PHP,php,curl,Php,Curl,我有一个前端代码 $ch = curl_init(); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //curl_setopt($ch, CURLOPT_HTTPHEADER

我有一个前端代码

$ch = curl_init();
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
//curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
curl_setopt($ch, CURLOPT_URL, $url);
//make the request
$responseJSON = curl_exec($ch);
$response_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($response_status == 200) { // success
    // remove any "problematic" characters from the json string and then decode
    if (debug) {
        echo "----finish API of getAPI inside basic_function with status==200---";
        echo "<br>";
        echo "-------the json response is-------" ;  //.$responseJSON;
        var_dump($responseJSON);
        //print_r($responseJSON);
        echo "<br>";
    }
    return json_decode( preg_replace( '/[\x00-\x1F\x80-\xFF]/', '', $responseJSON ) );
}
$output
在浏览器上显示为
{“状态”:“OK”,“数据”:“12345”}

然而,我回到了前端代码,做了
echo$responseJSON
,什么也没有得到。我认为
{“status”:“OK”,“data”:“12345”}
的输出将转到
$responseJSON
中。有什么想法吗

这是浏览器上的输出,有点奇怪!响应_状态为200,这在后端代码解析API之前就已经成功了。我希望status=200,json响应在{“status”:“OK”,“data”:“12345”}之后

=========================================================================================

在基本函数的GETAPI内部

-------url of cURL is -----http://localhost/test/api/session/login/?device_duid=website&UserName=joe&Password=1234&Submit=Submit



----finish API of getAPI inside basic_function with status==200---
-------the json response is-------string(1153) 


"************inside Backend API.php******************

---command of api is--/session/login/


---first element of api is--UserName=joe

--second element of api is---Password=1234

---third element of api is----Submit=Submit

----fourth element of api is---

-------inside session login of api-------------

{"status":"OK","data":"12345"}

您是否尝试过使用
curl\u setopt($ch,CURLOPT\u TIMEOUT,10)评论?
如果你评论那句话,看看会发生什么

还可以尝试使用基本代码,若这样做有效,那个么您稍后添加的内容是错误的:

// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, false);

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);
尝试变量转储($responseJSON)

如果返回false,请尝试

旋度误差($ch)

返回上次卷曲操作的明文错误消息


你确定你的$url是正确的吗?

你能发布服务器的头响应吗?对于特定的文件,确保它没有压缩它或需要HTTP验证$url是正确的,否则后端代码将不会拦截它并进行处理。var_dump($responseJSON)返回字符串(1153)。curl_error($ch)不返回任何内容。有了新的信息,我认为您已经在API调试消息中启用了某些内容,如果您关闭/删除它们,您应该会得到响应
// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, false);

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);