Symfony2和跨站点POST请求=>空数据 [英] Symfony2 and cross site POST request => empty data

查看:85
本文介绍了Symfony2和跨站点POST请求=>空数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过POST从远程服务器使用winhttp.winhttprequest.5.1将XML字符串发送到控制器. 在我的开发机上这样做可以很好地运行(将客户端和服务器托管在同一台机器上,具有相同的IP). 但是,当我的应用程序部署在生产服务器上时,POST数组为空.

I'm trying to send a XML string to a controller using winhttp.winhttprequest.5.1 from a remote server via POST. Doing so on my dev machine runs perfectly fine (hosting client and server on the same machine, same IP). Nevertheless, when my application is deployed on the production server, the POST array is empty.

我认为这可能是由于CSRF保护所致,但是即使我在config.yml中将其禁用,我的控制器仍然会获得空数据. 所以,我在这里很受困,不胜感激.

I think it might be due to CSRF protection, but even if I disable it in config.yml, my controller still get empty data. So, I'm quite stuck right here, would appreciate any help.

使用winhttp.winhttprequest.5.1发送数据

Sending data using winhttp.winhttprequest.5.1

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

Symfony2控制器:

Symfony2 Controller :

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

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

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

请求转储:

  • Dev机: [请求] => Symfony \ Component \ HttpFoundation \ ParameterBag对象(
    [parameters:protected] =>数组(
    [lcFile] => A1 005 LNBsLNBs5false2013-05-30T12:06:52201 blablabla

  • Dev machine : [request] => Symfony\Component\HttpFoundation\ParameterBag Object (
    [parameters:protected] => Array (
    [lcFile] => A1005LNBsLNBs5false2013-05-30T12:06:52201 blablabla

生产机器: [请求] => Symfony \ Component \ HttpFoundation \ ParameterBag对象(
[参数:受保护] =>数组())
[查询] => Symfony \ Component \ HttpFoundation \ ParameterBag对象(
[parameters:protected] =>数组

Prod machine : [request] => Symfony\Component\HttpFoundation\ParameterBag Object (
[parameters:protected] => Array ( ) )
[query] => Symfony\Component\HttpFoundation\ParameterBag Object (
[parameters:protected] => Array

两个环境都在PHP 5.4上运行Apache.

Both environment are running Apache with PHP 5.4.

我怀疑一些CSRF保护问题是,如果我将完全相同的XML字符串发送到生产服务器上的纯PHP脚本中(将POST数据转储到文件中),它将起作用. 如果我将这些数据发送到Symfony控制器,则请求为空...

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. If I send those datas to a Symfony controller, the request is empty...

谢谢.

推荐答案

使用OVH作为生产服务器,它设置了一个http防火墙,无法将POST数据发送到控制器(根目录上的.ovhconfig). 删除或设置正确后,我便可以发送这些数据.

Using OVH as a production server, it set a http firewall unabling to send POST data to controllers (.ovhconfig on root directory). Removing or setting it right allowed me to send those data.

 http.firewall=none

仍然感谢您的帮助.

这篇关于Symfony2和跨站点POST请求=>空数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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