zoukankan      html  css  js  c++  java
  • curl上传、下载、https登陆

    1、下载
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "ftp://127.0.0.1/downtest.txt"); 
    curl_setopt($ch, CURLOPT_HEADER,0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
    curl_setopt($ch, CURLOPT_TIMEOUT,300); 
    //设置用户名和密码 
    curl_setopt($ch, CURLOPT_USERPWD,"yuejide:123456"); 
    $outfile = fopen("test.txt","wb"); 
    curl_setopt($ch,CURL_FILE,$outfile); 
    $rtn = curl_exec($ch); 
    fclose($outfile); 
    if(!curl_errno($ch)){ 
    echo $rtn; 
    }else{ 
    echo 'curl error'.curl_errno($ch); 
    } 
    curl_close($ch);
    
    2、上传
    $ch = curl_init(); 
    $localfile = "ftp01.php"; 
    $fp = fopen($localfile,'r'); 
    curl_setopt($ch, CURLOPT_URL, "ftp://127.0.0.1/ftp01_upload.php"); 
    curl_setopt($ch, CURLOPT_HEADER,0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
    curl_setopt($ch, CURLOPT_TIMEOUT,300); 
    //设置用户名和密码 
    curl_setopt($ch, CURLOPT_USERPWD,"yuejide:123456"); 
    
    curl_setopt($ch, CURLOPT_UPLOAD,1); 
    curl_setopt($ch, CURLOPT_INFILE,$fp); 
    curl_setopt($ch, CURLOPT_INFILESIZE,filesize($localfile)); 
    $rtn = curl_exec($ch); 
    fclose($fp); 
    if(!curl_errno($ch)){ 
    echo "upload successfully"; 
    }else{ 
    echo 'curl_error'.curl_error($ch); 
    } 
    curl_close($ch);
    3、https
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://www.baidu.com"); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
    date_default_timezone_set('PRC'); 
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0); 
    $output = curl_exec($ch); 
    curl_close($ch); 
    echo $output;
  • 相关阅读:
    java list随机截取(洗牌)
    LINUX安装Docker及Portainer可视化界面
    总结一些选题
    深入理解BIO、NIO、AIO
    InnoDB和MyISAM存储引擎的区别
    MyBatis的解析和运行原理
    [杂项/无聊向]《美食大战老鼠》强卡最优策略搜索代码(非玩家勿入)
    CSP 2019 游记
    NOI 2019 游记
    Comet OJ
  • 原文地址:https://www.cnblogs.com/gide/p/4695525.html
Copyright © 2011-2022 走看看