Table of Contents


HTTP Helper

HttpHelper class allows you to create HTTP Post and HTTP Get calls to communicate with other external systems via the HTTPHelper Class. HTTPHelper provides the following static methods:

 

Methods

MethodArgumentsReturn ValueComments
GetHttpRequestInfo

HttpResponseInfo

This method makes an HTTP Get call. 
PostHttpRequestInfo

HttpResponseInfo

This method makes an HTTP Post call.

PutHttpRequestInfoHttpResponseInfoThis method makes an HTTP PUT call.
DeleteHttpRequestInfoHttpResponseInfoThis method makes an HTTP DELETE call.
PatchHttpRequestInfoHttpResponseInfoThis method makes an HTTP PATCH call.
DownloadFileHttpRequestInfoHttpFileResponseInfoThis method download a file from a server.

 

Examples

The example below shows how you can call out to an external or internal resource via HTTP GET:

var request = new HttpRequestInfo {
   Url = "Your URL",
   ContentType = MimeContentTypes.Json,
​   Accept = MimeContentTypes.Json,
};

// Optionally set your HTTP Headers
request.Headers.Add("Authorization", "Bearer <token>");

// Send the call and receive the response in String
var result = HttpHelper.Get(request);

if (result.StatusCode == 200)
{
     // Everything went well.
     var responseBody = result.Body;
}

 

The example below shows how you can call a HTTP POST resource by passing data parameters:

var request = new HttpRequestInfo {
   Url = "https://www.sampleRestfulUrl.com/savedata",
   ContentType = MimeContentTypes.Form
};

request.Headers.Add("Authorization","Bearer <token>");

// Passing parameters as application/x-www-form-urlencoded
var data = new Dictionary<string,object>() {
    { "firstname","Jean" },
    { "lastname", "Van Damme" },
    { "email", "jeanv@mycompany.com" }
};

// Set the request body
request.PostData = data.ToHttpRequestBody();

var result = HttpHelper.Post(request);

if (result.StatusCode == 200)
{
  // Everything went well.
  var responseBody = result.Body;
}