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
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;
}