Getting a POST variable

Use this for GET values: Request.QueryString[“key”] And this for POST values Request.Form[“key”] Also, this will work if you don’t care whether it comes from GET or POST, or the HttpContext.Items collection: Request[“key”] Another thing to note (if you need it) is you can check the type of request by using: Request.RequestType Which will be the … Read more

How do I print the content of httprequest request?

You can print the request type using: request.getMethod(); You can print all the headers as mentioned here: Enumeration<String> headerNames = request.getHeaderNames(); while(headerNames.hasMoreElements()) { String headerName = headerNames.nextElement(); System.out.println(“Header Name – ” + headerName + “, Value – ” + request.getHeader(headerName)); } To print all the request params, use this: Enumeration<String> params = request.getParameterNames(); while(params.hasMoreElements()){ String … Read more

Posting JSON data using AFNetworking 2.0

after searching docs and trying out some codes I got following as an example AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.requestSerializer = [AFJSONRequestSerializer serializer]; NSDictionary *params = @ {@”user” :txtUserName, @”pwd” :txtPwd }; [manager POST:URL_SIGNIN parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@”JSON: %@”, responseObject); } failure: ^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@”Error: %@”, error); }]; Also … Read more

Android, Java: HTTP POST Request

Here’s an example previously found at androidsnippets.com (the site is currently not maintained anymore). // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(“http://www.yoursite.com/script.php”); try { // Add your data List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair(“id”, “12345”)); nameValuePairs.add(new BasicNameValuePair(“stringdata”, “AndDev is Cool!”)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute … Read more

JSON vs Form POST

I’d say that both methods will work well it’s important that you stay consistent across your APIs. The option I would personally choose is simply sending the content as application/json. POST doesn’t force you to use application/x-www-form-urlencoded – it’s simply something that’s used a lot because it’s what webbrowsers use.

HttpPost vs HttpGet attributes in MVC: Why use HttpPost?

Imagine the following: [HttpGet] public ActionResult Edit(int id) { … } [HttpPost] public ActionResult Edit(MyEditViewModel myEditViewModel) { … } This wouldn’t be possible unless the ActionMethodSelectorAttributes HttpGet and HttpPost where used. This makes it really simple to create an edit view. All the action links just points right back to the controller. If the view … Read more

Model always null on XML POST

Two things: You don’t need quotes “” around the content type and accept header values in Fiddler: User-Agent: Fiddler Content-Type: application/xml Accept: application/xml Web API uses the DataContractSerializer by default for xml serialization. So you need to include your type’s namespace in your xml: <TestModel xmlns=”http://schemas.datacontract.org/2004/07/YourMvcApp.YourNameSpace”> <Output>Sito</Output> </TestModel> Or you can configure Web API to … Read more

How to see form data with enctype = “multipart/form-data” in Chrome debugger

I tested on my platform: Chrome 79.0.3945.130 (Official Build) (64-bit), Windows 10. I confirm that this problem remains on the up to date version of Chrome (as of 1/22/2020). To be precise, the problem I found in Chrome 79.0.3945.130 (and Chromium Edge 79.0.309.68 as well) is as follows: For a multipart/form-data POST request, if we … Read more