Symfony2将XML发送到远程URL [英] Symfony2 sending XML to a remote URL

查看:214
本文介绍了Symfony2将XML发送到远程URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将XML资料传送到远端网址。如何使用Symfony2以正确的方式执行此操作?

I would like to send XML data to a remote URL. How to do this in a proper way using Symfony2?

在使用curl的平面PHP中,等同于:

Equivalent in flat PHP using curl would be:

$ch = curl_init("http://website");
$request["queue"] = file_get_contents("file_to_send.xml");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($ch);
curl_close ($ch);


推荐答案

做它。不要忘记,保持简单。

Well, from here it looks like a good way to do it. Don't forget, keep it simple.

您可能想将它包装在一些类,将管理与其他服务器的通信。这样,它会更容易测试。

You might want to wrap it in some class that would manager communication with other servers. This way it would be more testable.

这篇关于Symfony2将XML发送到远程URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆