1

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.

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.

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 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');
...
}

Request dump :

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

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

Both environment are running Apache with PHP 5.4.

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...

Thank you.

David B.
  • 169
  • 3
  • 13

1 Answers1

2

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

Thanks for helping anyway.

David B.
  • 169
  • 3
  • 13
  • Could you please explain how did you remove or set the firewall right in order to get POST data properly ? – matdev Feb 18 '17 at 03:48
  • 1
    You are a really lucky I could get a hand on this old project. I updated the reply accordingly. Hope this helps. – David B. Feb 19 '17 at 22:07
  • Thanks David for digging that out. However, this is no solution for me: I still get empty data in my controller when sending POST data. It works fine when I run the web server on localhost though, weird. – matdev Feb 20 '17 at 09:32
  • This project was a one-shot and I don't work with OVH anymore for this kind of troubles. Neither did I work with Symfony again.Nevertheless, what is the PHP version on your server vs PHP version on your dev machine ? Can you get POST data in plain old PHP (without Symfony) on your prod environment ? – David B. Feb 20 '17 at 10:03
  • Another cause might be the url rewrite. As mentionned here : http://stackoverflow.com/a/1631999/1156542 – David B. Feb 20 '17 at 10:07