I need to send more than a Set-Cookie HTTP header using HttpWebRequest class.
Problem is first request.Headers.Add("Set-Cookie", "[cookie string]") adds the header as expected, but subsequent ones are concatenated in the first added header.
Default behavior complicates obtaning a set of cookies by the receiver of a given request, because isn’t that easy split the header again in separate cookies’ strings.
Is there any way of adding n times some header?
Perhaps some headers mustn’t be repeated, but Set-Cookie is a valid use case, because receiver should read more than a cookie.
Thank you.
After spending some time looking for an out-of-the-box solution, I ended implementing an extension method to
System.Net.WebHeaderCollection:Thanks to this wonderful extension method, I’m able to convert headers’ collection to a lookup, which allows duplicate keys, and at the end of the day, doing some processing, I get a list of all HTTP headers in separately:
I hope sharing my solution will be a good contribution, as I guess others had or are having a similar case use!