PHP CURL模拟提交数据 攻击N次方

 

 

 public function actionCurl(){
        
        $data['DATA']='{"NAME":"c","LEGEND":"c;c","GENDER":"","CITY":0,"BIRTHDAY":"","COMPANY":"","JOB":"","WEBSITE":"","ADDRESS":"","NOTE":"","CONTACTS":[],"IMS":[],"FLAGS":[]}';
        $headers=array();
        $headers[]='X-Requested-With:XMLHttpRequest';
        $headers[]='Cookie:token=3cedf24b188fd7ac57176256a2a14879-b419e6ebb414d661a6e86a30cd633ce5; PHPSESSID=ddfrjb4p8evu3cumgnsveet2o3; _ga=GA1.2.1014541392.1437467254; _gat=1';
        $headers[]='Referer:http://www.crm.com/newContact.php';
        $headers[]='Content-Type:application/x-www-form-urlencoded; charset=UTF-8';
        $headers[]='Content-Length:315';
        $headers[]='Host:www.crm.com';
        $headers[]='DNT:1';
        $headers[]='Pragma:no-cache';
        $headers[]='Connection:Keep-Alive';
        $headers[]='User-Agent:Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)';
        $headers[]='Accept:application/json, text/javascript, */*; q=0.01';
        $headers[]='Accept-Encoding:gzip, deflate';
        $headers[]='Accept-Language:zh-CN';

        for ($i = 0; $i < 10; $i++) {
            $res = $this->curls($data, 'http://www.crm.com/handler/handleAddContact.php ', 'POST', $headers);
            print_r($res);
        }
    }
    
    
        /**
     *   curl请求
     * @author lid
     * @param array $data   要请求的array数组
     * @param str $url      请求的地址
     * @param str $method   大写 POST   GET
     * @param array $headers   扩展包头信息
     * @return string     
     */
    public static  function curls($data, $url, $method = 'POST', $headers = array()) {
        
        $ch = curl_init();
        $method_upper = strtoupper($method);
        if ($method_upper == 'POST') {
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POSTFIELDS,  http_build_query($data));
        } else {
            $url = $url . (strpos($url, '?') ? '&' : '?') . (is_array($data) ? http_build_query($data) : $data);
            curl_setopt($ch, CURLOPT_URL, $url);
        }
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method_upper);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 20);
        if ($headers) {
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        }
        $tmpInfo = curl_exec($ch);
        if (curl_errno($ch)) {
            exit(curl_error($ch));
        }
        curl_close($ch);
        return $tmpInfo;
    }

 

 

 

CURLOPT_POSTFIELDS的这个设置中,亦可以直接发送数组的,但是这样做的后果是严重增加的请求的时间,耗时大约在2秒多,同样的操作用socket方式操作则正常,在毫秒级别。

 数组:curl_setopt($ch, CURLOPT_POSTFIELDS, $arrData);
 修改为:curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));

http_build_query — 生成 URL-encode 之后的请求字符串。

 

curl 发送XML数据

$xml = ('<xml>
<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don\'t forget me this weekend!</body>
</note></xml>');
$url = "https://wx.api.zf.com/wxnotify.php ";
$header[] = "Content-type: text/xml";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);
curl_close($ch);

 

转载于:https://www.cnblogs.com/dcb3688/p/4607974.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值