3

using

            var values = new Dictionary<string, string>
            {
               { "thing1", "hello" },
               { "thing2", "world" }
            };
            var content = new FormUrlEncodedContent(values);
            var response = await client.PostAsync("http://www.example.com/recepticle.aspx", content);

            var responseString = await response.Content.ReadAsStringAsync();

I have not seen an examnle with adding headers, only data values

1 Answer 1

2

FormUrlEncodedContent class inherits from HttpContent, which contains the Headers property, which you can use to add/remove/set the http headers.

The Headers property is an instance of HttpContentHeaders, so check that last class' docs to see the available methods and properties you can use to alter the headers you want.

Example:

var content = new FormUrlEncodedContent(values);
content.Headers.Add("MyHeader", "My Value");
content.Headers.ContentType = "application/pdf";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.