WebClient UploadString(url, data) Method Loses "Content-Type"/"application/json" Header After Invocation. RRS feed

  • Question

  • Hi, Everybody!

    I have noticed that after I invoke the WebClient UploadString(url, data) method, the WebClient "loses" the "Content-Type"/"application/json" header, but not the "api_key", "<api_key>" header.  If I choose to reuse the WebClient, I need to check if the "Content-Type"/"application/json" header is present and add it again before invoking the WebClient UploadString(url, data) method.

                    if (!webClient.Headers.AllKeys.Contains("Content-Type"))
                        webClient.Headers.Add("Content-Type", "application/json");
                    var response = webClient.UploadString(url, data);
    Is there an explanation for that?

    Thursday, December 28, 2017 3:45 PM

All replies