Definir cabeçalho ao chamar HTTPClient.PostAsync
Onde posso definir o cabeçalho como chamada de serviço REST ao usar HTTPClient simples?
Eu faço :
HttpClient client = new HttpClient();
var values = new Dictionary<string, string>
{
{"id", "111"},
{"amount", "22"}
};
var content = new FormUrlEncodedContent(values);
var uri = new Uri(@"https://some.ns.restlet.uri");
var response = await client.PostAsync(uri, content);
var responseString = await response.Content.ReadAsStringAsync();
UPD
O cabeçalho que eu não adiciono é:
{"Authorization":"NLAuth nlauth_account=5731597_SB1, [email protected], nlauth_signature=Pswd1234567, nlauth_role=3","Content-Type":"application/json"}
Devo seguir:
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Authorization", "NLAuth nlauth_account=5731597_SB1, [email protected], nlauth_signature=Pswd1234567, nlauth_role=3","Content-Type":"application/json");