DocSas/DSCAppEssentials/Helpers/Utility.cs
/// <summary>
/// HTTP post item as an asynchronous operation.
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="postData">The post data.</param>
/// <returns>Task&lt;System.String&gt;.</returns>
HTTP post item as an asynchronous operation.
HTTP post item as an asynchronous operation .
public static async Task<string> HttpPostItemAsync(string url, object postData)
        {
            string result = string.Empty;
            var str = ToJson(postData);
            HttpContent cont = new StringContent(str);
            using (HttpClient client = new HttpClient())
            {
                using (HttpResponseMessage response = await client.PostAsync(url, cont))
                {
                    using (HttpContent content = response.Content)
                    {
                        string data = await content.ReadAsStringAsync();
                        if (!string.IsNullOrWhiteSpace(data))
                        {
                            result = data;
                        }
                    }
                }
            }
            return result;
        }
public static async Task < string > HttpPostItemAsync ( string url , object postData ) { string result = string . Empty ; var str = ToJson ( postData ) ; HttpContent cont = new StringContent ( str ) ; using ( HttpClient client = new HttpClient ( ) ) { using ( HttpResponseMessage response = await client . PostAsync ( url , cont ) ) { using ( HttpContent content = response . Content ) { string data = await content . ReadAsStringAsync ( ) ; if ( ! string . IsNullOrWhiteSpace ( data ) ) { result = data ; } } } } return result ; }
HTTP post item as an asynchronous operation.
HTTP post item as an asynchronous operation .
None
url
string
None
postData
object
The post data.
The post data .