亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

php 發送url 方式

標簽:
PHP

方法一:HTTP函数发送方式

说明:$data为POST发送的数据:$key为参数名,$val为参数值

[php]view plaincopy

  1. $URL = "http://pre.payment.sdoa.sdo.com/";

  2. $data = $key1."=".val1."&".$key2."=".val2;

  3. $PostResult = http_post_data($BGWURL,$data );


    方法二:Curl Post数据

    [php]view plaincopy


    方法三:fsockopen方式

    说明:$data为POST发送的数据:$data为数组形式

    [php]view plaincopy


    1. function posttohost($url, $data) {

    2. $url = parse_url($url);

    3. if (!$url) return"couldn't parse url";

    4. if (!isset($url['port'])) { $url['port'] = ""; }

    5. if (!isset($url['query'])) { $url['query'] = ""; }

    6. $encoded = "";

    7. while (list($k,$v) = each($data)) {

    8. $encoded .= ($encoded ? "&" : "");

    9. $encoded .= rawurlencode($k)."=".rawurlencode($v);

    10. }

    11. $fp = fsockopen($url['host'], $url['port'] ? $url['port'] : 80);

    12. if (!$fp) return"Failed to open socket to $url[host]";

    13. fputs($fp, sprintf("POST %s%s%s HTTP/1.0/n", $url['path'], $url['query'] ? "?" : "", $url['query']));

    14. fputs($fp, "Host: $url[host]/n");

    15. fputs($fp, "Content-type: application/x-www-form-urlencoded/n");

    16. fputs($fp, "Content-length: " . strlen($encoded) . "/n");

    17. fputs($fp, "Connection: close/n/n");

    18. fputs($fp, "$encoded/n");

    19. $line = fgets($fp,1024);

    20. if (!eregi("^HTTP/1/.. 200", $line)) return;

    21. $results = ""; $inheader = 1;

    22. while(!feof($fp)) {

    23. $line = fgets($fp,1024);

    24. if ($inheader && ($line == "/n" || $line == "/r/n")) {

    25. $inheader = 0;

    26. }

    27. elseif (!$inheader) {

    28. $results .= $line;

    29. }

    30. }

    31. fclose($fp);

    32. return$results;

    33. }

    1. function _curl_post($url, $vars) {

    2. $ch = curl_init();

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

    4. curl_setopt($ch, CURLOPT_URL,$url);

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

    6. curl_setopt($ch, CURLOPT_HEADER, 0 ) ;

    7. curl_setopt($ch, CURLOPT_POSTFIELDS, "var=".$vars);

    8. $data = curl_exec($ch);

    9. curl_close($ch);

    10. if ($data)

    11. return$data;

    12. else

    13. return false;

    14. }


點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消