HttpClient POST call with header value

string ff = “{\”destination\”: \”http://localhost:58125/default.aspx\”,\”domain\”: { \”fullName\”: \”name\” }}”;

            var client = new HttpClient();

            var httpContent = new StringContent(ff, Encoding.UTF8, “application/json”);

            var request = new HttpRequestMessage();

            //request.Headers.Add(“Content-Type”, “application/json”);

            request.Headers.Add(“apikey”, “test”);

            request.RequestUri = new Uri(“https://url”);

            request.Content = httpContent;

            request.Method = HttpMethod.Post;

            var response = client.SendAsync(request).Result;

            var ss = response.Content.ReadAsStringAsync(); ;

            var json = ss.Result;

            JObject obj = JObject.Parse(json);

            string name = (string)obj[“name”];

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s