Tuesday, June 10, 2014

Step by step how to create a POST Web Request using the Fiddler application

       By Carmel Shvartzman
In this tutorial we'll learn how to send a POST Web Request using the Fiddler tool and an Asp.Net MVC application
We'll start with a working MVC application, which uses an SQL database, containing a Posts Controller to support all CRUD operations, and we'll create a new entry using Fiddler, showing as follows :



First of all, to create the POST request, we need to download Fiddler from this web site :


After installing it on your machine, open Fiddler and click the "Composer" window :



Then type in the URL and select "POST" request method from the list :


Also, add the HOST, ACCEPT, and CONTENT-TYPE Headers for the request (don't worry for the Content-Length, because Fiddler will count and fill that field).

Then, fill the Request Body :  be careful to respect the field names of the Entity you want to create, because MVC will try to bind your request body to the fields of the Entity according to field names and types :



If the Operation Contract (the WCF method which handles this HTTP verb) has been defined using the "RequestFormat" option as "JSON", we can send a JSON body with our request, as follows:




Press the "EXECUTE" button at the Composer, to send the request. If you set a breakpoint inside the POST Controller Action, you'll see the binding in action :



In the meantime, you can see the HTTP request sent by Fiddler :


Also, the request's body fields can be seen in Fiddler : in the "WebForms" tab of the "Inspectors":



After the request has been processed, the new entry is appended to the posts list, and appears in the main page:


That's all!! 
In this tutorial we've seen how to create a POST Web Request using the Fiddler application and an Asp.Net MVC application. 
Happy programming.....


כתב: כרמל שוורצמן