Table of Contents

Class HttpClientHelper

Namespace
SunamoHttp
Assembly
SunamoHttp.dll

Helper class for HttpClient operations If you want a replacement for the HttpRequestHelper class, use this

public class HttpClientHelper
Inheritance
HttpClientHelper
Inherited Members
Extension Methods

Properties

HttpClientInstance

Gets or sets the shared HttpClient instance

public static HttpClient HttpClientInstance { get; set; }

Property Value

HttpClient

HttpResponseMessage

Gets or sets the last HTTP response message

public static HttpResponseMessage? HttpResponseMessage { get; set; }

Property Value

HttpResponseMessage

Methods

GetResponse(string, HttpMethod, HttpRequestData?)

Gets the HTTP response from the specified address Return always HttpResponseMessage, can't return HttpWebResponse

public static Task<HttpResponseMessage> GetResponse(string address, HttpMethod method, HttpRequestData? httpRequestData = null)

Parameters

address string

The URL address

method HttpMethod

The HTTP method

httpRequestData HttpRequestData

The HTTP request configuration data (can be null)

Returns

Task<HttpResponseMessage>

The HTTP response message

GetResponseStream(string, HttpMethod, HttpRequestData)

Gets the response stream from the specified address

public static Task<Stream> GetResponseStream(string address, HttpMethod method, HttpRequestData httpRequestData)

Parameters

address string

The URL address

method HttpMethod

The HTTP method

httpRequestData HttpRequestData

The HTTP request configuration data

Returns

Task<Stream>

The response stream

GetResponseText(string, HttpMethod, HttpRequestData?)

Gets the response text from the specified address Return always HttpResponseMessage, can't return HttpWebResponse Same url: HttpClientHelper.GetResponseText - Exception: The remote server returned an error: (400) Bad Request., response is null HttpClientHelper.GetResponseText - really xml, exists response Pros: Better is HttpClientHelper because I can parse error Cons: HttpClientHelper.GetResponseText not return HttpWebResponse object, only HttpResponseMessage

public static Task<string> GetResponseText(string address, HttpMethod method, HttpRequestData? httpRequestData = null)

Parameters

address string

The URL address

method HttpMethod

The HTTP method

httpRequestData HttpRequestData

The HTTP request configuration data

Returns

Task<string>

The response text