Firefox live http headers, curley braces after Cache-Control: no-cache

后端 未结 1 1312
孤独总比滥情好
孤独总比滥情好 2021-01-25 21:08

I\'m setting up a php cURL script to replicate what I\'m seeing in the live headers. this is an example.

Cache-Control: no-cache
{\"username\":\"me@mydomain.com\         


        
1条回答
  •  离开以前
    2021-01-25 21:40

    this class that i wrote can help you

     function HeaderProc($response,$Run="",$String=1/*[Is 1 IF Use for String Mode ]*/){
              print_r($response);
              if($String==1){
                 $response=explode("\r\n",$response);  
              }
              $PartHeader=0;
              $out[$PartHeader]=array();
              while(list($key,$val)=each($response)){
                  $name='';
                  $value='';
                  $flag=false;
                  for($i=0;$iCookie=array();
           preg_replace_callback("~(.*?)=(.*?);~si",function($m){$this->Cookie[trim($m[1])]=trim($m[2]);},' '.$Cookie.'; ');
           return $this->Cookie;
        }
        function cURL($cookies=false,$cookie='cookies.txt',$compression='gzip',$proxy='') {
             $this->headers[] = 'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
             $this->headers[] = 'Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3'; 
             $this->headers[] = 'Accept-Encoding:gzip,deflate,sdch';
             $this->headers[] = 'Accept-Language:en-US,en;q=0.8';
             $this->headers[] = 'Cache-Control:max-age=0';
             $this->headers[] = 'Connection:keep-alive';
             $this->user_agent = 'User-Agent:Mozilla/5.0 (SepidarSoft [Organic Search Engine Crawler] Linux Edition) AppleWebKit/536.5 (KHTML, like Gecko) SepidarBrowser/1.0.100.52 Safari/536.5';
             $this->compression=$compression; 
             $this->proxy=$proxy; 
             $this->cookies=$cookies; 
             if ($this->cookies == TRUE) $this->cookie($cookie); 
        } 
        function cookie($cookie_file) { 
             if (file_exists($cookie_file)) { 
                $this->cookie_file=$cookie_file; 
             } else { 
                fopen($cookie_file,'w') or $this->error('The cookie file could not be opened. Make sure this directory has the correct permissions');
                $this->cookie_file=$cookie_file; 
                @fclose($this->cookie_file); 
             } 
        }
        function GET($url) { 
             $process = curl_init($url); 
             curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers); 
             curl_setopt($process, CURLOPT_HEADER, 1); 
             curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent); 
             if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file);
             if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file);
             curl_setopt($process,CURLOPT_ENCODING , $this->compression); 
             curl_setopt($process, CURLOPT_TIMEOUT, 30); 
             if ($this->proxy) curl_setopt($process, CURLOPT_PROXY, $this->proxy); 
             curl_setopt($process, CURLOPT_RETURNTRANSFER, 1); 
             curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1); 
             $response = curl_exec($process);
             $header_size = curl_getinfo($process,CURLINFO_HEADER_SIZE);
             $result['Header'] = HeaderProc(substr($response, 0, $header_size),'',1);
             foreach($result['Header'] as $HeaderK=>$HeaderP){
               foreach($HeaderP['Set-Cookie'] as $key=>$val){
                 $result['Header'][$HeaderK]['Set-Cookie'][$key]=$this->CookieAnalysis($val);
               }
             }
             $result['Body'] = substr( $response, $header_size );
             $result['HTTP_State'] = curl_getinfo($process,CURLINFO_HTTP_CODE);
             $result['URL'] = curl_getinfo($process,CURLINFO_EFFECTIVE_URL); 
             curl_close($process); 
             return $result; 
        }
        function POST($url,$data) { 
             $process = curl_init($url); 
             curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers); 
             curl_setopt($process, CURLOPT_HEADER, 1); 
             curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent); 
             if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file);
             if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file);
             curl_setopt($process, CURLOPT_ENCODING , $this->compression); 
             curl_setopt($process, CURLOPT_TIMEOUT, 30); 
             if ($this->proxy) curl_setopt($process, CURLOPT_PROXY, $this->proxy); 
             curl_setopt($process, CURLOPT_POSTFIELDS, $data); 
             curl_setopt($process, CURLOPT_RETURNTRANSFER, 1); 
             curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1); 
             curl_setopt($process, CURLOPT_POST, 1);
             $response = curl_exec($process); 
             $header_size = curl_getinfo($process,CURLINFO_HEADER_SIZE);
             $result['Header'] = HeaderProc(substr($response, 0, $header_size),'',1);
             foreach($result['Header'] as $HeaderK=>$HeaderP){
               foreach($HeaderP['Set-Cookie'] as $key=>$val){
                 $result['Header'][$HeaderK]['Set-Cookie'][$key]=$this->CookieAnalysis($val);
               }
             }
             $result['Body'] = substr( $response, $header_size );
             $result['HTTP_State'] = curl_getinfo($process,CURLINFO_HTTP_CODE);
             $result['URL'] = curl_getinfo($process,CURLINFO_EFFECTIVE_URL);
             curl_close($process); 
             return $result; 
        }
        function error($error) { 
             echo "
    cURL Error
    $error
    "; die; } }

    sample:

      $cc = new cURL(); 
      print_r( $cc->POST('http://www.domain.com','username=me@mydomain.com;password=mypass;namespaceId=50000003"'));
    

    for old php

    function HeaderProc($response,$Run="",$String=1/*[Is 1 IF Use for String Mode ]*/){
              if($String==1){
                 $response=explode("\r\n",$response);  
              }
              $PartHeader=0;
              $out[$PartHeader]=array();
              while(list($key,$val)=each($response)){
                  $name='';
                  $value='';
                  $flag=false;
                  for($i=0;$iCookie=array();
           preg_match("~(.*?)=(.*?);~si",' '.$Cookie.'; ',$M);
           $this->Cookie[trim($M[1])]=trim($M[2]);
           return $this->Cookie;
        }
        function cURL($cookies=false,$cookie='cookies.txt',$compression='gzip',$proxy='') {
             $this->headers[] = 'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
             $this->headers[] = 'Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3'; 
             $this->headers[] = 'Accept-Encoding:gzip,deflate,sdch';
             $this->headers[] = 'Accept-Language:en-US,en;q=0.8';
             $this->headers[] = 'Cache-Control:max-age=0';
             $this->headers[] = 'Connection:keep-alive';
             $this->user_agent = 'User-Agent:Mozilla/5.0 (SepidarSoft [Organic Search Engine Crawler] Linux Edition) AppleWebKit/536.5 (KHTML, like Gecko) SepidarBrowser/1.0.100.52 Safari/536.5';
             $this->compression=$compression; 
             $this->proxy=$proxy; 
             $this->cookies=$cookies; 
             if ($this->cookies == TRUE) $this->cookie($cookie); 
        } 
        function cookie($cookie_file) { 
             if (file_exists($cookie_file)) { 
                $this->cookie_file=$cookie_file; 
             } else { 
                fopen($cookie_file,'w') or $this->error('The cookie file could not be opened. Make sure this directory has the correct permissions');
                $this->cookie_file=$cookie_file; 
                @fclose($this->cookie_file); 
             } 
        }
        function GET($url) { 
             $process = curl_init($url); 
             curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers); 
             curl_setopt($process, CURLOPT_HEADER, 1); 
             curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent); 
             if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file);
             if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file);
             curl_setopt($process,CURLOPT_ENCODING , $this->compression); 
             curl_setopt($process, CURLOPT_TIMEOUT, 30); 
             if ($this->proxy) curl_setopt($process, CURLOPT_PROXY, $this->proxy); 
             curl_setopt($process, CURLOPT_RETURNTRANSFER, 1); 
             curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1); 
             $response = curl_exec($process);
             $header_size = curl_getinfo($process,CURLINFO_HEADER_SIZE);
             $result['Header'] = HeaderProc(substr($response, 0, $header_size),'',1);
             foreach($result['Header'] as $HeaderK=>$HeaderP){
               if(!is_array($HeaderP['Set-Cookie']))continue;
               foreach($HeaderP['Set-Cookie'] as $key=>$val){
                 $result['Header'][$HeaderK]['Set-Cookie'][$key]=$this->CookieAnalysis($val);
               }
             }
             $result['Body'] = substr( $response, $header_size );
             $result['HTTP_State'] = curl_getinfo($process,CURLINFO_HTTP_CODE);
             $result['URL'] = curl_getinfo($process,CURLINFO_EFFECTIVE_URL); 
             curl_close($process); 
             return $result; 
        }
        function POST($url,$data) { 
             $process = curl_init($url); 
             curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers); 
             curl_setopt($process, CURLOPT_HEADER, 1); 
             curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent); 
             if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file);
             if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file);
             curl_setopt($process, CURLOPT_ENCODING , $this->compression); 
             curl_setopt($process, CURLOPT_TIMEOUT, 30); 
             if ($this->proxy) curl_setopt($process, CURLOPT_PROXY, $this->proxy); 
             curl_setopt($process, CURLOPT_POSTFIELDS, $data); 
             curl_setopt($process, CURLOPT_RETURNTRANSFER, 1); 
             curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1); 
             curl_setopt($process, CURLOPT_POST, 1);
             $response = curl_exec($process); 
             $header_size = curl_getinfo($process,CURLINFO_HEADER_SIZE);
             $result['Header'] = HeaderProc(substr($response, 0, $header_size),'',1);
             foreach($result['Header'] as $HeaderK=>$HeaderP){
                if(!is_array($HeaderP['Set-Cookie']))continue;
               foreach($HeaderP['Set-Cookie'] as $key=>$val){
                 $result['Header'][$HeaderK]['Set-Cookie'][$key]=$this->CookieAnalysis($val);
               }
             }
             $result['Body'] = substr( $response, $header_size );
             $result['HTTP_State'] = curl_getinfo($process,CURLINFO_HTTP_CODE);
             $result['URL'] = curl_getinfo($process,CURLINFO_EFFECTIVE_URL);
             curl_close($process); 
             return $result; 
        }
        function error($error) { 
             echo "
    cURL Error
    $error
    "; die; } }

    sample:

      $cc = new cURL(); 
      print_r( $cc->POST('http://www.domain.com','username=me@mydomain.com;password=mypass;namespaceId=50000003"'));
    

    0 讨论(0)
提交回复
热议问题