简体   繁体   English

Symfony2和跨站点POST请求=>空数据

[英]Symfony2 and cross site POST request => empty data

I'm trying to send a XML string to a controller using winhttp.winhttprequest.5.1 from a remote server via POST. 我正在尝试通过POST从远程服务器使用winhttp.winhttprequest.5.1将XML字符串发送到控制器。 Doing so on my dev machine runs perfectly fine (hosting client and server on the same machine, same IP). 在我的开发机上这样做可以很好地运行(将客户端和服务器托管在同一台机器上,具有相同的IP)。 Nevertheless, when my application is deployed on the production server, the POST array is empty. 但是,当我的应用程序部署在生产服务器上时,POST数组为空。

I think it might be due to CSRF protection, but even if I disable it in config.yml, my controller still get empty data. 我认为这可能是由于CSRF保护所致,但是即使我在config.yml中将其禁用,我的控制器仍然会获得空数据。 So, I'm quite stuck right here, would appreciate any help. 因此,我在这里很受困,不胜感激。

Sending data using winhttp.winhttprequest.5.1 使用winhttp.winhttprequest.5.1发送数据

loObj.Open("POST", url, .F.)
loObj.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
loObj.Send("lcFile=" + parsedContent)

Symfony2 Controller : Symfony2控制器:

public function getStockFromLogisticsXMLStringAction(Request $request)
{
    $request = $this->get('request');

    $xml = "";
    $output = $this->get('webservice.response');

    if ($request->getMethod() == 'POST') 
        $xml = $request->request->get('lcFile');
...
}

Request dump : 请求转储:

  • Dev machine : [request] => Symfony\\Component\\HttpFoundation\\ParameterBag Object ( 开发人员机器:[请求] => Symfony \\ Component \\ HttpFoundation \\ ParameterBag对象(
    [parameters:protected] => Array ( [参数:受保护] =>数组(
    [lcFile] => A1 005 LNBsLNBs5false2013-05-30T12:06:52201 blablabla [lcFile] => A1 005 LNBsLNBs5false2013-05-30T12:06:52201 blablabla

  • Prod machine : [request] => Symfony\\Component\\HttpFoundation\\ParameterBag Object ( 产品机器:[请求] => Symfony \\ Component \\ HttpFoundation \\ ParameterBag对象(
    [parameters:protected] => Array ( ) ) [参数:受保护] =>数组())
    [query] => Symfony\\Component\\HttpFoundation\\ParameterBag Object ( [查询] => Symfony \\ Component \\ HttpFoundation \\ ParameterBag对象(
    [parameters:protected] => Array [参数:受保护] =>数组

Both environment are running Apache with PHP 5.4. 两种环境都运行带有PHP 5.4的Apache。

The fact I'm suspecting some CSRF protection issue is that if I send the exact same XML string to a pure PHP script on the production server dumping the POST data into a file, it works. 我怀疑存在一些CSRF保护问题的事实是,如果我将完全相同的XML字符串发送到生产服务器上的纯PHP脚本(将POST数据转储到文件中),它将起作用。 If I send those datas to a Symfony controller, the request is empty... 如果我将这些数据发送到Symfony控制器,则请求为空...

Thank you. 谢谢。

Using OVH as a production server, it set a http firewall unabling to send POST data to controllers (.ovhconfig on root directory). 使用OVH作为生产服务器,它设置了http防火墙,无法将POST数据发送到控制器(根目录上的.ovhconfig)。 Removing or setting it right allowed me to send those data. 删除或设置正确后,我便可以发送这些数据。

 http.firewall=none

Thanks for helping anyway. 无论如何,感谢您的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM