How to making a post using custom headers

  • Thread starter Thread starter Henrique Mendes Carvalho
  • Start date Start date
H

Henrique Mendes Carvalho

Guest
How to send the following json, in a post, with the headers?

{
"from":"WineShop",
"to":[
"5531984882884",
"5531984882886"
],
"text":"Wine shop grand opening at Monday 8pm. Don't forget glasses."
}


Headers Authorization and Content-Type.

My code:

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Net.Http;using System.Web.Http;using System.Net;namespace appService.Utils{ public class SendSMS { public static async System.Threading.Tasks.Task SendSMSToKeeperAsync(List<string> numbers, string usuario) { var request = new HttpClient(); int count = 0; string keerpersNumbers = ""; string urlSMS = "https://myurl.com"; string authHeader = "Basic bWFsYWxhaTpzd0JIMjAxNiE="; string contentTypeHeader = "application/json"; if (numbers != null && numbers.Count > 0) { foreach (string num in numbers) { //keerpersNumbers = num; if (count > 0) { keerpersNumbers = keerpersNumbers + "," + num; } else { keerpersNumbers = num; } count++; } if (usuario == null && usuario.Equals("")) { usuario = "app"; } } string myJson = "{from:"+usuario+","+"to:["+keerpersNumbers+"],text:Some text}"; var response = await request.PostAsync(urlSMS, new StringContent(myJson, System.Text.Encoding.UTF8, "application/json")); } }}

Continue reading...
 
Back
Top