我如何在 php 中使用 curl 执行下面的代码?
因为 fopen 在服务器端有问题。这个示例代码片段是关于 wizIQ API 的使用...
class HttpRequest
{
function wiziq_do_post_request($url, $data, $optional_headers = null)
{
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
if ($optional_headers !== null)
{
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = fopen($url, 'r+',false, $ctx);
if (!$fp)
{
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false)
{
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
}//end class HttpRequest