php curl

巴扎黑
Release: 2016-11-22 16:37:43
Original
1102 people have browsed it

<?php
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,"http://www.test.net/test.php?user_id=qdapplicant");
//是否返回头信息
curl_setopt($ch,CURLOPT_HEADER,0);
//设置数据不直接输出(如果设置了直接输出,则curl_exec返回值为空)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
//CURLOPT_TIMEOUT 设置cURL允许执行的最长秒数。  
//CURLOPT_TIMEOUT_MS 设置cURL允许执行的最长毫秒数。  
//CURLOPT_CONNECTTIMEOUT 在发起连接前等待的时间,如果设置为0,则无限等待。  
//CURLOPT_CONNECTTIMEOUT_MS 尝试连接等待的时间,以毫秒为单位。如果设置为0,则无限等待。 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
//接收数据(返回值是字符串)
$sContent = curl_exec($ch);
curl_close($ch);
//为便于数据传输,源数据一般使用json_decode编码,故而此处json_decode解码
$sContent = json_decode($sContent);
//由于编码的差异,有时需要编码的转换
$sContent = mb_convert_encoding($sContent, "GBK", "UTF-8");
print_r($sContent);
Copy after login


Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!