CURL
- curl是利用URL语法在命令行方式下工作的开源文件传输工具。它被广泛应用在Unix、多种Linux发行版中,并且有DOS和Win32、Win64下的移植版本。
- CURL课程
- CURL参数
<?php
$curl = curl_init('https://www.baidu.com/');//初始化
curl_exec($curl);//执行
curl_close($curl);//关闭
<?php
$curl = curl_init();
curl_setopt($curl,CURLOPT_URL,"https://www.baidu.com/");//设置url为
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);//不直接打印出来
$output = curl_exec($curl);//内容赋给一个变量
curl_close($curl);
echo str_replace('百度','屌丝',$output);
<?php
$data = sprintf('<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<getWeatherbyCityName xmlns="http://WebXml.com.cn/">
<theCityName>%s</theCityName>
</getWeatherbyCityName>
</soap:Body>
</soap:Envelope>','北京');
$curlobj = curl_init();
curl_setopt($curlobj, CURLOPT_URL, "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx");
curl_setopt($curlobj, CURLOPT_POST, 1);
curl_setopt($curlobj, CURLOPT_HEADER, 0);
curl_setopt($curlobj, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlobj, CURLOPT_POSTFIELDS, $data);
curl_setopt($curlobj, CURLOPT_HTTPHEADER, array("Content-Type: application/soap+xml; charset=utf-8",
"Content-length: ".strlen($data),
"SOAPAction:\"http://WebXml.com.cn/getWeatherbyCityName\""));
$rtn = curl_exec($curlobj);
if(!curl_errno($curlobj)){
$info = curl_getinfo($curlobj);
print_r($info);
echo "RETURN: " . $rtn;
} else {
echo 'Curl error: ' . curl_error($curlobj);
}
curl_close($curlobj);
?>