NMackay

Badges

Third Anniversary2500 Comments250 Answers500 LikesSecond Anniversary250 Likes100 Answers1000 Comments100 Likes50 Answers500 CommentsFirst Anniversary25 Answers25 Likes5 Answers100 CommentsPhotogenicFirst Answer5 Likes10 CommentsName DropperFirst Comment

About

Username
NMackay
Location
GB
Joined
Visits
3,595
Last Active
Roles
Insider, University
Points
4,524
Twitter
@normanmackay3
LinkedIn URL
https://uk.linkedin.com/in/norman-mackay-05622b
Badges
22

NMackay ✭✭✭✭✭

About

Username
NMackay
Location
GB
Joined
Visits
3,595
Last Active
Roles
Insider, University
Points
4,524
Twitter
@normanmackay3
LinkedIn URL
https://uk.linkedin.com/in/norman-mackay-05622b
Badges
22
  • Re: Web service post request

    I do something like this

    public static async Task<List<T>> PostFetchList(string url, object toPost, CancellationToken ct, Dictionary<string, string> headers = null)
            {
                var httpClient = new HttpClient();
                HttpContent content = new StringContent(JsonConvert.SerializeObject(toPost), Encoding.UTF8, WebConstants.ContentTypeJson);
    
                if (!Equals(headers, null))
                {
                    foreach (var header in headers)
                    {
                        content.Headers.Add(header.Key, header.Value);
                    }
                }
    
                var response = await httpClient.PostAsync(new Uri(url), content, ct);
    
                if (!response.IsSuccessStatusCode)
                {
                    switch (response.StatusCode)
                    {
                        case HttpStatusCode.Unauthorized: