from a php curl request to a symfony2 app (symfony controller - Symfony\Bundle\FrameworkBundle\Controller)
<?php
$string1 = 'foo';
$string2 = 'bar';
$string3 = 'foobar';
$url = 'http://mysitename.com/path/to/symfony2/app';
$myVars = 'var1='.urlencode($string1).'&var2='.urlencode($string2).'&var3='.urlencode($string3);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $myVars);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
curl_close($ch);
The response on the symfony app is:
var_dump($request); //Symfony\Component\HttpFoundation\Request
...
["request"]=>
object(Symfony\Component\HttpFoundation\ParameterBag)#4 (1) {
["parameters":protected]=>
array(0) {
}
}
["query"]=>
object(Symfony\Component\HttpFoundation\ParameterBag)#5 (1) {
["parameters":protected]=>
array(0) {
}
}
...
the response from a standard php file:
<?php
var_dump($_POST);
is:
array(3) {
["var1"]=>
string(3) "foo"
["var2"]=>
string(3) "bar"
["var3"]=>
string(6) "foobar"
}
tried setting csrf_protection to false in config.yml to no avail
when posting from a form e.g. http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_form_submit and changing the action to my symfony2 controller i can get the correct response:
...
["request"]=>
object(Symfony\Component\HttpFoundation\ParameterBag)#4 (1) {
["parameters":protected]=>
array(0) {
}
}
["query"]=>
object(Symfony\Component\HttpFoundation\ParameterBag)#5 (1) {
["parameters":protected]=>
array(2) {
["FirstName"]=>
string(6) "Mickey"
["LastName"]=>
string(5) "Mouse"
}
}
...
any help will be appreciated
edit:
shows:
* About to connect() to host.com port 80 (#38)
* Trying xxx.xxx.xxx.xxx...
* Connected to host.com (xxx.xxx.xxx.xxx) port 80 (#38)
> POST /path/to/controller HTTP/1.1
User-Agent: Mozila 6.0
Host: host.com
Accept: */*
Referer: http://my/local/env/public
Content-Length: 103
Content-Type: application/x-www-form-urlencoded
* upload completely sent off: 103 out of 103 bytes
< HTTP/1.1 301 Moved Permanently
< Date: Tue, 25 Mar 2014 20:15:25 GMT
< Server: Apache
< Location: http://host.com/path/to/controller
< Vary: Accept-Encoding
< Content-Length: 269
< Connection: close
< Content-Type: text/html; charset=iso-8859-1
<
* Closing connection 38
* Issue another request to this URL: 'http://host.com/path/to/controller'
* Violate RFC 2616/10.3.2 and switch from POST to GET
* About to connect() to host.com port 80 (#39)
* Trying xxx.xxx.xxx.xxx...
* Connected to host.com (xxx.xxx.xxx.xxx) port 80 (#39)
> GET /path/to/controller HTTP/1.1
User-Agent: Mozila 6.0
Host: host.com
Accept: */*
Referer: http://my/local/env/public
< HTTP/1.1 500 Internal Server Error
< Date: Tue, 25 Mar 2014 20:15:25 GMT
< Server: Apache
< X-Powered-By: PHP/5.4.26
< Cache-Control: no-cache
< Vary: Accept-Encoding
< Connection: close
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=UTF-8
<
* Closing connection 39
internal server error is expected as it fails to parse the missing post data