PHP5中如何接收并处理通过POST请求的XML文件?
我想在 PHP5 中使用 simeplexml 类来处理一个小的 XML 文件。但要获取该文件,脚本必须向远程服务器发送特定的 POST 请求,该服务器将“给出”一个 XML 文件作为回报。所以我相信我不能使用“simplexml_load_file”方法。该文件仅用于处理,然后它可以,甚至应该消失/删除。 我有这种类型的 HTTP 标头
$header = 'POST '.$gateway.' HTTP/1.0'."\r\n" .
'Host: '.$server."\r\n".
'Content-Type: application/x-www-form-urlencoded'."\r\n".
'Content-Length: '.strlen($param)."\r\n".
'Connection: close'."\r\n\r\n";
,但不太知道下一步该怎么做。有 fsockopen 但我不确定这是否合适或如何使用它。
I want to use simeplexml class in PHP5 to handle a small XML file. But to obtain that file, script has to send a specific POST request to a remote server that will "give" me an XML file in return. So I believe I can't use the "simplexml_load_file" method. This file is needed just for processing, then it can, or even should, be gone/deleted.
I've got HTTP HEADER of this type
$header = 'POST '.$gateway.' HTTP/1.0'."\r\n" .
'Host: '.$server."\r\n".
'Content-Type: application/x-www-form-urlencoded'."\r\n".
'Content-Length: '.strlen($param)."\r\n".
'Connection: close'."\r\n\r\n";
And not much idea of what to do next with that. There is fsockopen but I'm not sure if that would be appropriate or how to go with it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的建议是使用 Zend_Http_Client 库或 cURL 之类的东西。使用 fsockopen 使一切正确将是调试的痛苦。
Zend_Http_Client 有一个很好的界面并且可以很好地工作。
CURL 也不是太麻烦,并且已经是大多数 PHP 构建的一部分。
下面的例子:
My advice would be use something like Zend_Http_Client library or cURL. Getting everything right with fsockopen will be a pain to debug.
Zend_Http_Client has a nice interface and would work fabulously.
CURL isn't too much of a pain either and is already a part of most PHP builds.
Example below:
我会使用 HTTP 客户端库,例如 Zend_Http_Client (或 cURL如果您是受虐狂)创建 POST 请求,然后将响应正文输入 simplexml_load_string 或
SimpleXMLElement::__construct()
I'd use an HTTP client library like Zend_Http_Client (or cURL if you're a masochist) to create the POST request, then feed the response body into simplexml_load_string or
SimpleXMLElement::__construct()