Page 1 of 1

Legen Sie die Header des Autorisierungs-/Inhaltstyps fest, wenn Sie httpclient.postasync aufrufen

Posted: 19 Aug 2025, 17:00
by Anonymous
Wo kann ich Header auf den REST -Service -Anruf einstellen, wenn ich einfaches httpclient verwendete? < /p>

Ich mache: < /p>

Code: Select all

HttpClient client = new HttpClient();
var values = new Dictionary
{
{"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();
< /code>

upd < /p>

Headers [url=viewtopic.php?t=14917]Ich möchte[/url] hinzufügen: < /p>

{
"Authorization": "NLAuth nlauth_account=5731597_SB1, [email protected], nlauth_signature=Pswd1234567, nlauth_role=3",
"Content-Type": "application/json"
}
< /code>

Soll ich Folgendes machen? < /p>

client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Authorization", "NLAuth nlauth_account=5731597_SB1, [email protected], nlauth_signature=Pswd1234567, nlauth_role=3","Content-Type":"application/json");