Symfony2 sending XML to a remote URL
I would like to send XML data to a remote URL. How to do this in a proper开发者_如何转开发 way using Symfony2?
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.
精彩评论