• 响应头location 页面跳转


    登陆;http://192.168.32.161/DEVOPS/index.php/Index/do_login
    
    
    Cache-Control	no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    Connection	    Keep-Alive
    Content-Encoding	gzip
    Content-Length	    23
    Content-Type	    text/html; charset=UTF-8
    Date	            Fri, 23 Sep 2016 14:16:49 GMT
    Expires	            Thu, 19 Nov 1981 08:52:00 GMT
    Keep-Alive	        timeout=5, max=95
    Location	        /DEVOPS/index.php/Main/index
    Pragma	            no-cache
    Server	            Apache/2.2.31 (Unix) PHP/5.6.20
    Vary	            Accept-Encoding
    X-Powered-By	    PHP/5.6.20
    
    
    	function do_login(){
    		//获取用户名和密码信息,和数据库中比对
    		// echo 111111111;
    		// dump($_POST);
    		// dump($_SESSION);
    		$username=$_POST['username'];
    		$password=$_POST['password'];
    		$code=$_POST['code'];
    		if($_SESSION['verify']!==md5($code)){
    			$this->error('验证码错误');
    		}
    		
    		$m=new Model('user');
    		$where['username']=$username;
    		$where['password']=md5($password);
    		
    		$arr = $m->where($where)->find();
    		
    		$i=$m->where($where)->count();
    		
    		if ($i>0){
    			$_SESSION['username']=$username;
    			$_SESSION['authority'] = $arr['authority'];
    			$this->redirect('Main/index');
    		}else{
    			$this->error('该用户不存在');
    		}
    	}
    	
    	登陆成功后跳转到Main/index页面
    	
    	http://192.168.32.161/DEVOPS/index.php/Main/index
    	
    	
    	use Net::SMTP;
    use LWP::UserAgent;
    use HTTP::Cookies;
    use HTTP::Headers;
    use HTTP::Response;
    use Encode;
    use Switch;
    use File::Temp qw/tempfile/;
    use HTTP::Date qw(time2iso str2time time2iso time2isoz);
    my $CurrTime = time2iso( time() );
    my $ua       = LWP::UserAgent->new;
    $ua->timeout(10);
    $ua->env_proxy;
    my $now = time();
    $ua->agent('Mozilla/5.0');
    my $cookie_jar = HTTP::Cookies->new(
    
        file           => 'lwp_cookies.txt',
        autosave       => 1,
        ignore_discard => 1
    );
    $ua->cookie_jar($cookie_jar);
    
    my $response = $ua->get("http://192.168.32.161/DEVOPS/index.php/Public/code"
    
                );
                if ( $response->is_success ) {
                    $r = $response->decoded_content;
    
                    # print $response->decoded_content;  # or whatever
                }
                else {
                    die $response->status_line;
                };
    			     my ( $fh, $filename ) =
                  tempfile( "wj_qrcode_XXXX", SUFFIX => ".jpg", DIR => 'c:\' );
                binmode $fh;
                print $fh $r;
                close $fh;
                print "登录二维码已经下载到本地 [ $filename ] 
    ";
    
    
    ##打开图片
                system("start $filename ");
    
                my $validCode = <STDIN>;
                chomp $validCode;
                print "$validCode is $validCode
    ";
    			 my $login_url =
                  'http://192.168.32.161/DEVOPS/index.php/Index/do_login';
    
                my $res = $ua->post(
                    $login_url,
                    {
                        
                        'username'  => 'admin',
                        
                        'password'  => 'admin',
                        'code' => "$validCode"
                    }
                );
                print "---------------
    ";
    
                ##判断响应头里面的location,确定是否登陆成功 
    			 my $content = $res->as_string()  ;
    			 my $content = encode( "gbk", decode( "utf8", "$content" ) );
                 print "$content is $content
    ";
              #获取的是原始内容,包括响应头,响应正文 
    			   
                  print $res->header('Location');
    			  
    			  
    返回;
    F:>perl php.pl
    登录二维码已经下载到本地 [ C:wj_qrcode_kz0X.jpg ]
    9017
    $validCode is 9017
    ---------------
    $content is HTTP/1.1 302 Found
    Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    Connection: close
    Date: Fri, 23 Sep 2016 14:42:17 GMT
    Pragma: no-cache
    Location: /DEVOPS/index.php/Main/index
    Server: Apache/2.2.31 (Unix) PHP/5.6.20
    Vary: Accept-Encoding
    Content-Length: 3
    Content-Type: text/html; charset=UTF-8
    Expires: Thu, 19 Nov 1981 08:52:00 GMT
    Client-Date: Fri, 23 Sep 2016 14:45:09 GMT
    Client-Peer: 192.168.32.161:80
    Client-Response-Num: 1
    X-Powered-By: PHP/5.6.20
    
    /DEVOPS/index.php/Main/index

  • 相关阅读:
    《哈佛商业评论》2018正刊12期与增刊25期的点评
    《财经》2018年共30+1期的点评与摘抄
    4星|《人人都在说谎》:社会科学方面有趣的数据分析方法与结论
    3星|侯世达《我是个怪圈》:关于人类意识的各种哲学思辨
    虚拟机 SUSE Linux Enterprise Server 12 SP2 64
    虚拟机 CentOS7 64
    虚拟机 ubuntu 16.04
    虚拟机 windows xp sp3 原版
    C#实现控制Windows系统关机、重启和注销的方法
    日期时间设置 "2018-05-04T16:36:23.6341371+08:00" 格式
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13350222.html
Copyright © 2020-2023  润新知