Maison > Questions et réponses > le corps du texte
Library
public function doRequest($url, $para)
{
do {
if(extension_loaded('curl')) {
$ch = curl_init();
$options = array(
CURLOPT_URL => $url,
CURLOPT_HEADER => 0,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $para,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSLVERSION => 1,
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'],
);
curl_setopt_array($ch, $options);
$data = curl_exec($ch);
$info = curl_getinfo($ch);
$error = curl_error($ch);
curl_close($ch);
if(get_magic_quotes_gpc()) {
$data = stripslashes($data);
}
$decode = json_decode($data, true);
if(json_last_error() === JSON_ERROR_NONE) {
$err = array(
'status' => 'success',
'results' => $info,
);
}
else
{
$err = array(
'status' => 'failed',
'results' => '返回值非JSON 类型',
);
}
} else {
$err = array(
'status' => 'failed',
'results' => '请开启PHP Curl 拓展',
);
}
return $err;
} while(0);
}
Controller
public function how_old()
{
$url = config_item('how_old_url');
$data = array(
'isTest' => false,
'faceName' => 'Test',
'faceUrl' => 'http://www.sinaimg.cn/dy/slidenews/4_img/2015_12/704_1579346_230297.jpg',
);
$this->load->library('cuiqg');
var_dump( $this->cuiqg->doRequest($url, $data))];
}
Browser
奇怪 没有任何 打印 他是怎么显示出来的 ,在一个
gettype()
doRequest()
$data 是bool 类型的 怎么处理, 还有就是这些转义字符怎么去掉 ~_~||
黄舟2017-04-10 15:37:39
$url="http://how-old.net/Home/Analyze";
$data = array(
'isTest' => false,
'faceName' => 'Test',
'faceUrl' => 'http://www.sinaimg.cn/dy/slidenews/4_img/2015_12/704_1579346_230297.jpg',
);
function post( $url, $params, $cookie ="")
{
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($params));
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
$result = post($url,$data);
var_dump(json_decode(json_decode($result)));