我有一些麻煩,從服務器獲取XML響應,這是我第一次有 使用cURL在PHP中使用XML編碼(張貼解析XML到服務器,並接收響應XML) - 所有的代碼如下:獲取響應XML和重定向與PHP捲曲
HTML:
<html>
<head>
<title>test</title>
</head>
<body>
<form action="3FieldSample.php" method="post" enctype="multipart/form-data" >
<div class="form-field title">
<div class="input select"><label for="title">Title</label>
<select name="title" id="title" value="mr">
<option value="mr">Mr</option>
<option value="mrs">Mrs</option>
<option value="dr">Dr</option>
<option value="miss">Miss</option>
<option value="ms">Ms</option>
</select></div> </div>
<div class="form-field float-left">
<div class="input select"><label for="fname">First Name</label>
<input name="fname" value="" maxlength="150" width="100%" type="text" id="fname" /></div>
</div>
<div class="form-field float-left">
<div class="input text"><label for="ApplicationPaydayAppLastName">Last Name</label>
<input name="lname" value="" maxlength="150" type="text" id="lname"/></div>
</div>
<div class="submit">
<input type="image" src = "submit.jpg" width="25%" alt="submit" id="submit">
</div>
</form>
</body>
</html>
======================= ========================
處理:
<?php
header('Content-Type: text/xml');
$xmldoc = new DomDocument('1.0');
$xmldoc->preserveWhiteSpace = false;
$xmldoc->formatOutput = true;
$url = "http://thesite_2_post_2.com/process.php";
$title = $_POST['title'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$post_string = '<?xml version="1.0" encoding="UTF-8"?>
<lead>
<applicant>
<title>'. $title.'</title>
<fname>'. $fname.'</fname>
<lname>'. $lname.'</lname>
</applicant>
</lead>';
$header = "POST HTTP/1.0 \r\n";
$header .= "Content-type: text/xml \r\n";
//#$header .= "Content-type: text/html \r\n";
$header .= "Content-length: ".strlen($post_string)." \r\n";
$header .= "Content-transfer-encoding: text \r\n";
#$header .= "Connection: close \r\n\r\n";
$header .= $post_string;
print ($post_string);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $header);
###curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
curl_close($ch);
$objResult = json_decode($data);
#
# This is an example of how I'm supposed to deal with the response?
#
#
$_SESSION['price'] = 0;
if ($objResult->purchased == 1) {
$_SESSION['price'] = $objResult->price;
$url = urlencode($objResult->redirect_url);
header('Location: '.$url);
print $objResult;
}
else
{
echo "something went wrong";
}
?>
上面最後片段是的,我應該如何處理這我沒有得到響應的例子。 這是我得到的輸出:此頁面包含以下錯誤:第8行第8列的錯誤: :文檔結尾處的額外內容。以下是頁面渲染到第一個錯誤。
先生彼得格里芬
當我認爲我得到這個輸出(無領導主題標籤)來源:
#<?xml version="1.0" encoding="UTF-8"?>
#<lead>
#<applicant>
#<title>mr</title>
#<fname>peter</fname>
#<lname>griffin</lname>
#</applicant>
#</lead>something went wrong
從服務器得到響應的XML任何幫助將不勝感激。
而你的問題是?這是錯誤信息嗎?什麼是你不清楚?另外請重新創建一個從頭開始的示例,並根據需要以儘可能少的數據和代碼展示您的問題。這通常可以幫助您消除任何錯誤。 – hakre 2014-10-11 15:33:15