php中运用http调用的GET和POST方法示例
更新时间:2014年09月29日 17:26:02 投稿:whsnow
调用的GET和POST方法,使用到的函数是curl_init, curl_setopt, curl_exec,curl_close,默认是GET方法
使用到的函数是curl_init, curl_setopt, curl_exec,curl_close。
默认是GET方法,可以选择是否使用Header:
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "$url"); curl_setopt($ch, CURLOPT_TIMEOUT, 2); curl_setopt($ch, CURLOPT_HEADER, 1); //如果设为0,则不使用header curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); $result = curl_exec($ch); curl_close($ch);
POST方法:
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'$url');
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
$vars =sprintf('from=%d&to=%d&subject=%s&body=%s',$from, $to, urlencode($subject), urlencode($body));
curl_setopt($ch,CURLOPT_POSTFIELDS,$vars);
$ret = curl_exec($ch);
curl_close($ch);
相关文章
解决PHP程序运行时:Fatal error: Maximum execution time of 30 seconds
最近做的程序中涉及到的循环比较多且处理的情况较复杂,在运行程序时出现执行超时提示如下:Fatal error: Maximum execution time of 30 seconds exceeded in D:\php\AppServ\www\sum3\test.php on line 3通过在网上搜索,找到了解决方法和大家分享,下面来一起看看吧。2016-11-11


最新评论