PHP CURL類比POST提交XML資料_PHP教程

來源:互聯網
上載者:User
本文章來給大家介紹一個利用PHP CURL類比POST提交XML資料,因為接受方只接受xml資料所以我就寫了一個,下面分享給各位朋友,有需要的朋友可參考。
代碼如下 複製代碼


$url = "http://www.bkjia.com/ login";

$ch = curl_init();
$header[] = "Content-type: text/xml";//定義content-type為xml
curl_setopt($ch, CURLOPT_URL, $url); //定義表單提交地址
curl_setopt($ch, CURLOPT_POST, 1); //定義提交類型 1:POST ;0:GET
curl_setopt($ch, CURLOPT_HEADER, 1); //定義是否顯示狀態頭 1:顯示 ; 0:不顯示
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);//定義請求類型
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);//定義是否直接輸出返迴流
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //定義提交的資料,這裡是XML檔案
curl_close($ch);//關閉

再來介紹一個POST表單提交的案例

代碼如下 複製代碼

//首先要引用這個類
include("/data/tools/pooy/Snoopy/Snoopy.class.php");
$snoopy = new Snoopy;
//$Parameters這個是要提交的數組
$Parameters["username"] = "user";
$Parameters["pass"] = "pass";
$file = "/test/test.jpg";
$serviceUrl = "http://www.test.com/fileProcess.php";
$postfiles["image"] = $file; //$filename上傳檔案相對路徑 例如"upload/taoav.jpg";image/jpg
$snoopy->_submit_type = "multipart/form-data"; //設定submit類型
$snoopy->submit($serviceUrl,$Parameters,$postfiles);


http://www.bkjia.com/PHPjc/444618.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/444618.htmlTechArticle本文章來給大家介紹一個利用PHP CURL類比POST提交XML資料,因為接受方只接受xml資料所以我就寫了一個,下面分享給各位朋友,有需要的朋友...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.