我有一个表单将信息发送到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