Access POST values in Symfony2 request object

The form post values are stored under the name of the form in the request. For example, if you’ve overridden the getName() method of ContactType() to return “contact”, you would do this: $postData = $request->request->get(‘contact’); $name_value = $postData[‘name’]; If you’re still having trouble, try doing a var_dump() on $request->request->all() to see all the post values.

ios Upload Image and Text using HTTP POST

Here’s code from my app to post an image to our web server: // Dictionary that holds post parameters. You can set your post parameters that your server accepts or programmed to accept. NSMutableDictionary* _params = [[NSMutableDictionary alloc] init]; [_params setObject:[NSString stringWithString:@”1.0″] forKey:[NSString stringWithString:@”ver”]]; [_params setObject:[NSString stringWithString:@”en”] forKey:[NSString stringWithString:@”lan”]]; [_params setObject:[NSString stringWithFormat:@”%d”, userId] forKey:[NSString stringWithString:@”userId”]]; … Read more

How to post raw body data with curl?

curl’s –data will by default send Content-Type: application/x-www-form-urlencoded in the request header. However, when using Postman’s raw body mode, Postman sends Content-Type: text/plain in the request header. So to achieve the same thing as Postman, specify -H “Content-Type: text/plain” for curl: curl -X POST -H “Content-Type: text/plain” –data “this is raw data” http://78.41.xx.xx:7778/ Note that … Read more

Get all variables sent with POST?

The variable $_POST is automatically populated. Try var_dump($_POST); to see the contents. You can access individual values like this: echo $_POST[“name”]; This, of course, assumes your form is using the typical form encoding (i.e. enctype=”multipart/form-data” If your post data is in another format (e.g. JSON or XML, you can do something like this: $post = … Read more

Send json post using php

You can use CURL for this purpose see the example code: $url = “your url”; $content = json_encode(“your data to be sent”); $curl = curl_init($url); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, array(“Content-type: application/json”)); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $content); $json_response = curl_exec($curl); $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); if ( $status != 201 ) { … Read more

How to retrieve form values from HTTPPOST, dictionary or?

You could have your controller action take an object which would reflect the form input names and the default model binder will automatically create this object for you: [HttpPost] public ActionResult SubmitAction(SomeModel model) { var value1 = model.SimpleProp1; var value2 = model.SimpleProp2; var value3 = model.ComplexProp1.SimpleProp1; … … return something … } Another (obviously uglier) … Read more

How to use getJSON, sending data with post method?

The $.getJSON() method does an HTTP GET and not POST. You need to use $.post() $.post(url, dataToBeSent, function(data, textStatus) { //data contains the JSON object //textStatus contains the status: success, error, etc }, “json”); In that call, dataToBeSent could be anything you want, although if are sending the contents of a an html form, you … Read more