PHP如何以post形式傳送xml資料

2021-07-02 04:16:49 字數 1843 閱讀 8538

php如何以post形式傳送xml資料,php如何接收xml檔案

傳送xml:postxml.php

$xmldata = "

1366181013< /createtime>

5867702771251151243< /msgid>

";

//第一種傳送方式,也是推薦的方式:

$url = ''; //接收xml資料的檔案

$header = "content-type: text/xml"; //定義content-type為xml,注意是陣列

$ch = curl_init ($url);

curl_setopt($ch, curlopt_url, $url);

curl_setopt($ch, curlopt_returntransfer,true);

curl_setopt($ch, curlopt_httpheader,$header); //防止出現驗證錯誤curl_setopt($ch, curlopt_ssl_verifypeer, false);curl_setopt($ch, curlopt_ssl_verifyhost, false);

curl_setopt($ch, curlopt_post, 1);

curl_setopt($ch,curlopt_postfields, $xmldata);

$response = curl_exec($ch);

if(curl_errno($ch))

curl_close($ch);

//第二種傳送方式:

$url = '';

$header = "content-type:text/xml";//定義content-type為xml

接收xml: getxml.php

//將xml資料寫入文字檔案"a.txt"中

$handle =fopen('a.txt','a+');

fwrite($handle,$xml);

問題:為什麼不使用$_post接收?

擴充套件閱讀:

使用php curl的post資料

** 小公尺哥的專欄

PHP PHP如何以post形式傳送xml資料

2019獨角獸企業重金招聘python工程師標準 php如何以post形式傳送xml資料,php如何接收xml檔案 準備兩個php檔案 乙個是傳送資料的postxml.php,另乙個是接收資料的getxml.php 傳送xml postxml.php 準備xml資料 xmldata ad775b21...

PHP 如何以檔案形式輸出給前端

一般web大部分通訊都是依靠http來傳輸,http規定了資訊的組成部分。只要修改對應的返回http頭,就能告訴客戶端返回的資料型別。廢話不多說了,直接上 將路徑檔案輸出給前端 將程式的輸出以檔案形式輸出 forcedownload test.txt 你好呀 將伺服器上的檔案輸出給前端 將內容以檔案...

傳送POST請求(HTTP),K V形式

傳送post請求 http k v形式 param url param params author charlie.chen return publicstaticstring dopost string url,map params if list.size 0 執行post請求,返回respon...