什么测试工具可以压力测试HTTPSPOST的

2022-03-31 教育 127阅读

什么测试工具可以压力测试HTTPSPOST的

  • classHttp{

  • publicstatic$default_options=array(

  • 'User-Agent'=>'Mozilla/5.0(WindowsNT6.1;WOW64)AppleWebKit/537.4(KHTML,likeGecko)Chrome/22.0.1229.94Safari/537.4',

  • 'Connection'=>'Close'//NeedtoclosetherequesteverytimeforHTTP1.1

  • );

  • privatestaticfunctiongetHeaders($options){

  • if($options===NULL){

  • //Usedefaultoptions

  • $options=self::$default_options;

  • }else{

  • //Mergethe$optionswith$default_options,ifthevaluesetin$options,

  • //Valuein$default_optionswillbeoverwrite

  • $options=$options+self::$default_options;

  • }

  • $headers=array();

  • foreach($optionsas$k=>$v){

  • $headers[]=$k.':'.$v;

  • }

  • return$headers;

  • }

  • publicstaticfunctionget($url,array$options=NULL,$data=NULL,&$response_header=NULL){

  • $headers=self::getHeaders($options);

  • $params=array('http'=>array(

  • 'method'=>'GET',

  • //DefautlHTTP1.1andwithConnectionClose

  • 'protocol_version'=>'1.1'

  • ));

  • if($options!==null){

  • $params['http']['header']=$headers;

  • }

  • if($data){

  • $url.='?'.http_build_query($data); 

  • }

  • $ctx=stream_context_create($params);

  • $fp=fopen($url,'rb',false,$ctx);

  • if(!$fp){

  • thrownewException("Connectionfailed:$url");

  • }

  • if($response_header!==NULL){

  • $response_header=stream_get_meta_data($fp);

  • }

  • $response=stream_get_contents($fp);

  • if($response===false){

  • thrownewException("ReadingdataFailed:$url");

  • }

  • fclose($fp);

  • return$response;

  • }

  • publicstaticfunctionpost($url, $options=null,$data=NULL,&$response_header=NULL){

  • //RestrictedtheFormformate

  • if(is_array($data)){

  • $data=http_build_query($data);

  • }

  • $options['Content-type']='application/x-www-form-urlencoded';

  • $options['Content-Length']=strlen($data);

  • $params=array('http'=>array(

  • 'method'=>'POST',

  • 'content'=>$data

  • ));

  • $headers=self::getHeaders($options);

  • $params['http']['header']=$headers;

  • $ctx=stream_context_create($params);

  • $fp=fopen($url,'rb',false,$ctx);

  • if(!$fp){

  • thrownewException("ConnectionFailed:$url");

  • }

  • if($response_header!==NULL){

  • $response_header=stream_get_meta_data($fp);

  • }

  • $response=stream_get_contents($fp);

  • if($response===false){

  • thrownewException("Readingdatafailed:$url");

  • }

  • fclose($fp);

  • return$response;

  • publicstaticfunctioninflate($_content){

  • //deflateadd10charatersbeforeinflateformatand8charaterschecksumappend

  • //gzdecodeisnotavailibleforALLPHPevengzencodeisavalible

  • $_content=substr($_content,10,-8); 

  • returngzinflate($_content);

  • }

  • publicstaticfunctionisZipped($_response_header){

  • if(preg_grep('/^Content-Encoding:\s*gzip/',$_response_header['wrapper_data'])){

  • returnTRUE;

  • }else{

  • returnFalse;

  • }

  • }

  • }//Endhttp

声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com