Posted By

xzkcz on 03/28/10


Tagged

curl php post


Versions (?)

PHP forge POST


 / Published in: PHP
 

URL: http://www.zishu.cn/blogview.asp?logID=891

  1. <?php
  2. $post_data = array();
  3. $post_data['text'] = $_POST['text']; //要POST的数据
  4.  
  5. $url = 'http://abc.baidu.com'; //目标地址
  6. $o = '';
  7. foreach ($post_data as $k => $v) $o .= '$k='.urlencode($v).'&';
  8.  
  9. $post_data = substr($o , 0,-1);
  10. $ch = curl_init();
  11. curl_setopt($ch, CURLOPT_POST, 1);
  12. curl_setopt($ch, CURLOPT_HEADER, 0);
  13. curl_setopt($ch, CURLOPT_URL,$url);
  14. curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
  15. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  16. $result = curl_exec($ch);
  17. ?>

Report this snippet  

You need to login to post a comment.