Userbn
Userbn

Reputation: 342

Symfony2 Create Post Response

I would like to create a POST response in symfony2 using the component Symfony\Component\HttpFoundation\Response How can i simulate a POST, by changing the header values

Thanks

Upvotes: 0

Views: 665

Answers (2)

topaz1008
topaz1008

Reputation: 215

Code example:

$curl_opts = array(
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_URL            => 'http://myserver.com/dataRoute',
    CURLOPT_POSTFIELDS     => json_encode($json),
    CURLOPT_HTTPHEADER     => array('Content-Type: application/json')
);

$curl = curl_init();
curl_setopt_array($curl, $curl_opts);
$result = curl_exec($curl);
curl_close($curl);

var_dump($result);

or by using JavaScript & jQuery

var url = '/dataRoute';
var postData = {
    'key1': value1,
    'key2': value2
};
$.post(url, postData, function(data) {
    console.log(data);
});

Upvotes: 0

Moritz
Moritz

Reputation: 559

HTTP Responses do not have a method. Only Requests have. You can create one with curl, for example.

Upvotes: 2

Related Questions