我有一個表單將信息發送到api並獲得XML格式的響應。我需要知道什麼是記錄/解析結果(文本文檔或其他)的最佳方式。如果可能的話,我希望所有回覆都保存在一個文檔中,而不是每個結果的單個文檔。將XML結果保存到文檔或數據庫中
我使用AJAX POST方法,並在結果代碼需要的localproxy代碼如下
<?php
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, 'http://integrate.com/api/test.ashx');
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $_POST);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);
curl_close($ch);
file_put_contents('mydata.xml', $result, FILE_APPEND);
die('<h1>Thanks!</h1>');
?>
的XML數據來自於以下
<result>
<success>0</success>
<leadid/>
<errors>
<error>Missing Field: </error>
</errors>
</result>
文件獲取格式創建而現在它有內容,這是內容,這是一個錯誤
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request - Invalid Content Length</h2>
<hr><p>HTTP Error 400. There is an invalid content length or chunk length in the request.</p>
</BODY></HTML>
請問這個 意思? api服務器不接受請求嗎?
你正在尋找一種方法來解析XML?爲此目的有很多基本的文檔。有用的Google查詢包括'php parse xml',它可以讓您瞭解可用庫的概況。 – 2012-08-16 23:11:22