public function urlGetContent(params = null, json = false)
{
ch, CURLOPT_URL, ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt(ch, CURLOPT_HEADER, 0);
if ($method == 'POST') {
curl_setopt($ch, CURLOPT_POST, true);
if ($json && is_array($params)) {
$params = json_encode($params);
}
if (is_string($params) || is_array($params)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
} else {
// error_log("Argument \$params should be an array of parameters or (if you want to send raw data) a string");
return false;
}
if ($json) { //发送JSON数据
curl_setopt($ch, CURLOPT_HTTPHEADER,
array(
'Content-Type: application/json; charset=utf-8',
'Content-Length:' . strlen($params),
}
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
网友评论