2015-12-18 59 views
1

我是一个SOAP领域和事物的新手,并不完全知道如何正常工作,但我收到来自eBay的邮件正文中包含肥皂消息的通知。通常一个帖子消息似乎是:如何使用symfony获得完整的帖子内容?

{'id':300} 

因此,我们可以通过名称使用例如$_POST['id']得到进去。 SOAP消息发布作为一个字符串是这样的:

<?xml... 

使用纯PHP,我会做file_get_contents('php://input')

所以,我的问题很简单:如何使用Symfony获得此消息?或者我应该做file_get_contents('php://input')

+1

你提的问题是非常不清楚,缺乏细节,并且你已经完成的工作。请考虑更新它并阅读https://stackoverflow.com/help/how-to-ask – tchap

回答

4

使用Request对象获取内容,然后您可以使用DomCrawler遍历节点并查找内容。

例子:

use Symfony\Component\DomCrawler\Crawler; 

... 

public function apiAction(Request $request) 
{ 
    $xmlContent = $request->getContent(); 
    $crawler = new Crawler($xmlContent); 

    $text = $crawler 
     ->filter('node > childnode') 
     ->text(); 
} 
+1

祝你好运json_decoding XML! – Oldskool

+0

@Oldskool,他指出,帖子主体看起来像'{'id':300}',它是json格式 –

+1

不,OP表示发布消息*通常*看起来像那样,但他/她现在获得SOAP消息,这是XML。 – Oldskool