PHP 透過CURL post xml資料到遠端位址
1、CURL POST方法
$ch = curl_init();
$timeout = 30;
curl_setopt($ch, CURURPTPT, $top*, $top*; CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type:text/xml; charset=utf-8"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0. CURLOPT_POSTFIELDS, $data);//Post提交的封包
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, $churl_HEADER, 0);
header('Content-Type:text/xml; charset=utf-8');
2、下面是XML資料
提交之後 一直報錯
This page contains the following errors:
Below is a rendering of the page up to the first error.
回覆內容:
1、CURL POST方法$ch = curl_init();
$timeout = 30;
curl_setopt($ch, CURURPTPT, $top*, $top*; CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type:text/xml; charset=utf-8"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0. CURLOPT_POSTFIELDS, $data);//Post提交的資料包
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, $churl_HEADER, 0);
curl_close($ch);
提交之後 一直報錯 error on line 1 at column 50: Space required after the Public Identifier 查詢XML封包資料資訊 沒有錯誤,求大俠解決 是CURL方法寫的不對 還是其他問題
有時候遠端伺服器錯誤回傳的是類似500錯誤一樣,這時候回傳的資料就不是xml的,建議你列印一下。
謝謝邀請。提交之後報錯誤?建議你在提交之後做個斷點輸出看看是不是有什麼錯誤訊息。具體原因只能一點點的輸出去找看
This page contains the following errors:
Below is a rendering of the page up to the first error.<code>$ch = curl_init();
$timeout = 30;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type:text/xml; charset=utf-8"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);//Post提交的数据包
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HEADER, 0);
$result = curl_exec($ch);
curl_close($ch);
echo $result;</code>