全省快速服務,舊屋翻修、廠房拆除等大小工程
價格透明線上可查,事後清運還原
台北居家清潔推薦NO1搬家公司,免費紙箱,服務不打烊
打包家當不煩惱,落地不加價,歡迎來電預約估價

首頁  •  tw 論壇 • 程式設計討論     • 

[php] 用CURL進行POST發送數據

房東:威威
發表時間:2012-07-17
[檢舉]



\"我頂\" 字號:

1、POST代碼



  1. <?php

  2. //請求頁面

  3. $address=array(

  4. \'street\'=>$_POST[\'street\'],

  5. \'city\'=>$_POST[\'city\']

  6. );

  7.  

  8.  

  9. $ch = curl_init("http://211.151.109.51/work/test1.php");

  10. curl_setopt($ch,CURLOPT_POST,1);

  11. curl_setopt($ch,CURLOPT_POSTFIELDS,$address);

  12. $ret = curl_exec($ch);

  13. curl_close($ch);

  14.  

  15.  

  16. ?>



2、發送文件代碼



  1. <?php

  2.  

  3.    $post_data = array();

  4.    

  5.    $post_data[\'pictures[0]\'] = "@cat.jpg";

  6.    $post_data[\'pictures[1]\'] = "@dog.jpg";

  7.    

  8.  

  9.    $ch = curl_init();

  10.    curl_setopt($ch, CURLOPT_URL, "http://my.domain.com/my_url.php" );

  11.    curl_setopt($ch, CURLOPT_POST, 1 );

  12.    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

  13.    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  14.    $postResult = curl_exec($ch);

  15.  

  16.    if (curl_errno($ch)) {

  17.        print curl_error($ch);

  18.    }

  19.    curl_close($ch);

  20.    print "$postResult";

  21. ?>







原文地址:http://bbs.chinaunix.net/thread-748708-1-1.html



********************************************************************



附:CURL普通操作代碼

1、http的get實現



$ch = curl_init("http://www.jb51.net/") ;

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ;

curl_setopt($ch, CURLOPT_BINARYTRANSFER, true) ;

$output = curl_exec($ch) ;

$fh = fopen("out.html", \'w\') ;

fwrite($fh, $output) ;

fclose($fh) ;



2、http的post實現



//extract data from the post

extract($_POST) ;

//set POST variables

$url = \'http://www.jb51.net/get-post.php\' ;

$fields = array(

\'lname\'=>urlencode($last_name) ,

\'fname\'=>urlencode($first_name) ,

\'title\'=>urlencode($title) ,

\'company\'=>urlencode($institution) ,

\'age\'=>urlencode($age) ,

\'email\'=>urlencode($email) ,

\'phone\'=>urlencode($phone)

);

//url-ify the data for the POST

foreach($fields as $key=>$value) { $fields_string .= $key.\'=\'.$value.\'&\' ; }

rtrim($fields_string ,\'&\') ;

//open connection

$ch = curl_init() ;

//set the url, number of POST vars, POST data

curl_setopt($ch, CURLOPT_URL,$url) ;

curl_setopt($ch, CURLOPT_POST,count($fields)) ;

curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_string) ;

//execute post

$result = curl_exec($ch) ;

//close connection

curl_close($ch) ;



原文地址:http://www.jb51.net/article/15554.htm

http://merry05.blog.hexun.com.tw/69484190_d.html






  • 贊助網站       

    廣利不動產-板橋在地生根最實在--新板特區指名度最高、值得您信賴的好房仲
    完整房訊,房屋、店面熱門精選物件,廣利不動產 優質仲介,房屋租賃、買賣資訊透明,交易真安心!
    廣利不動產-新板特區指名度最高、值得您信賴的好房仲
    您的托付,廣利用心為您服務

  • 1 樓住戶:jack
    發表時間:2012-07-17
    [檢舉]



    //請求頁面

    $address=array(

    'hidden_d_name'=>$_POST['jackreewwwlwlwlw'],
    'heidden_sld%5Bcom.tw%5D'=>$_POST['com.tw'],
    'select_year%5Bcom.tw%5D'=>$_POST['D0903241601COMTW01'],
    'text_passwd%5Bcom.tw%5D'=>$_POST['budweiser'],
    'text_check_passwd0'=>$_POST['budweiser'],
    'app_cname'=>$_POST['%B6%C0%ADP%B8R'],
    'app_ename'=>$_POST['james+huang'],
    'app_id'=>$_POST['A12103033'],
    'app_cellphone'=>$_POST['0930420500'],
    'app_tel_top'=>$_POST['02'],
    'app_tel_center'=>$_POST['2956544'],
    'app_tel_down'=>$_POST['2222'],
    'app_fax_top'=>$_POST['3333'],
    'app_fax_center'=>$_POST['3333'],
    'app_email1'=>$_POST['[email protected]'],
    'app_email2'=>$_POST['[email protected]'],
    'text_zipcode'=>$_POST['100'],
    'text_cmp_caddr'=>$_POST['%A5x%A5_%A5%AB%A4%A4%A5%BF%B0%CF%AAL%B4%CB%ABn%B8%F4142%B8%

    B911%BC%D3'],
    'text_cmp_eaddr'=>$_POST['6F.%2C+No.47%2C+Wujhou+St.%2C+Wanhua+District%

    2C+Taipei+Ci&whois=0'],
    'scmp_cname'=>$_POST[' '],
    'sapp_cname'=>$_POST[''],
    'scmp_id'=>$_POST[''],
    'sapp_email'=>$_POST[''],
    'sapp_tel_top'=>$_POST[''],
    'sapp_tel_center'=>$_POST[''],
    'sapp_tel_down'=>$_POST[''],
    'sapp_cellphone'=>$_POST[''],
    'scmp_zipcode'=>$_POST[''],
    'scmp_caddr'=>$_POST['']
    );





    $ch = curl_init("http://rs.apol.com.tw/add_product.php");

    curl_setopt($ch,CURLOPT_POST,1);

    curl_setopt($ch,CURLOPT_POSTFIELDS,$address);

    $ret = curl_exec($ch);

    curl_close($ch);


    echo"$ret";


    ?>


    2 樓住戶:jack
    發表時間:2012-07-18
    [檢舉]



    $ch = curl_init('http://rs.apol.com.tw/dns-4-1.php');
    curl_setopt ($ch, CURLOPT_POST, 1);
    curl_setopt ($ch, CURLOPT_POSTFIELDS, "d_name=jacksfss22&checkbox%5Bcom.tw%5D=com.tw");

    $output = curl_exec($ch);
    curl_close($ch);


    ?>




     共 2 人回應  選擇頁數 【第1 頁】 

    姓名:
    佈告內容: