我发现CURLOPT_HTTPHEADER发送header头信息,不设置,请求时也会自动生成头部信息,不影响请求数据
2016-08-30
$xml = simplexml_load_string($tmp);
//echo $xml->string[11];
$array = array(
'0'=>'省份',
'1'=>'城市',
'2'=>'经纬度',
'3'=>'天气图片',
'4'=>'时间',
'5'=>'温度'
);
//print_r($xml->string);
foreach ($array as $key => $value) {
echo $value.":".$xml->string[$key]."<br/>";
}
//echo $xml->string[11];
$array = array(
'0'=>'省份',
'1'=>'城市',
'2'=>'经纬度',
'3'=>'天气图片',
'4'=>'时间',
'5'=>'温度'
);
//print_r($xml->string);
foreach ($array as $key => $value) {
echo $value.":".$xml->string[$key]."<br/>";
}
2016-08-30
把获取的结果用simplexml_load_string转换成迭代对象后,可以用下面的方式获取指定数据
$xml = simplexml_load_string($tmp);
echo $xml->string[11];
$xml = simplexml_load_string($tmp);
echo $xml->string[11];
2016-08-30
单色彩虹的答案比较完整,但做到获取结果只需要
$post = 'theCityCode=' . urlencode('杭州') . '&theUserID='; //post数据
$curl = curl_init();
$header[] = 'User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36';
$post = 'theCityCode=' . urlencode('杭州') . '&theUserID='; //post数据
$curl = curl_init();
$header[] = 'User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36';
2016-08-10
curl_setopt($curl, CURLOPT_HTTPHEADER, $header); //curl_opt_http_header包装请求头
curl_setopt($curl, CURLOPT_URL, 'http://ws.webxml.com.cn/WebServices/WeatherWS.asmx/getWeather');
curl_setopt($curl, CURLOPT_URL, 'http://ws.webxml.com.cn/WebServices/WeatherWS.asmx/getWeather');
2016-08-10
curl_setopt($curl, CURLOPT_HEADER, 0); //如果你想把一个头包含在输出中,设置这个选项为一个非零值。
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //结果缓存,不直接输出
curl_setopt($curl, CURLOPT_POST, 1); //设置为post请求,否则默认为get
curl_setopt($curl, CURLOPT_POSTFIELDS, $post); //post的数据
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //结果缓存,不直接输出
curl_setopt($curl, CURLOPT_POST, 1); //设置为post请求,否则默认为get
curl_setopt($curl, CURLOPT_POSTFIELDS, $post); //post的数据
2016-08-10
$response = curl_exec($curl);
curl_close($curl);
$xml = simplexml_load_string($response);
print_r($xml);
curl_close($curl);
$xml = simplexml_load_string($response);
print_r($xml);
2016-08-10
请求头里需要伪装成浏览器,
$header[] = 'User-Agent: xx';
$header[] = 'User-Agent: xx';
2016-08-10