How to send a POST request

For this tutorial we'll send an HTTP POST request to a REST Service (written in C#).

The signature of the method that we'll be invoking is shown below.

[WebInvoke(UriTemplate = "", Method = "POST")]
public SampleItem Create(SampleItem instance)
{
   this.myCollection.Add(instance);
   return instance;
}

The function "Create" takes an instance of the class SampleItem via a POST at the URL http://localhost:1753/Service1.  It can be sent as JSON or XML.  If succesful, it simply echoes back the SampleItem instance. Below is the definition of the SampleItem class

public class SampleItem
{
  
public int Id { get; set; }
  
public string StringValue { get; set; }
}

 

 To send a JSON POST request, please follow the steps below

  1. Run WcfStorm.Rest.exe
  2. In URL, type http://localhost:1753/Service1/
  3. Select the method "POST"
  4. In the request headers, add Content-Type: application/json. This step is necessary because we want to tell the REST Service that data we're sending is in the JSON format.
  5. In the Request Parameters panel, paste-in a JSON instance of the SampleItem Class.
  6. Click Send.



     

To send an XML POST Request:

  1. To send a POST request in XML format, change the Content-Type in the header to, "application/xml" or "text/xml"
  2. In the request body, paste in an instance of the SampleItem class in XML format.

     

 


Site Map | Printable View | © 2008 - 2024 WCFStorm Solutions

Powered by mojoPortal | XHTML 1.0 | CSS | Design by styleshout