Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
342 views
in Technique[技术] by (71.8m points)

c# - Using WebClient keeps changing json to text/plain for Content-Type

I'm using WebClient and I set the headers to JSON yet when I look at Fiddler, it shows text/plain. I do not understand why. I have to use WebClient (older app).

How do I enforce JSON to be sent in the request as Content-Type?

My relevant code:

            var webClient = new WebClient();
            webClient.Headers.Add(HttpRequestHeader.ContentType, "application/json; charset=utf-8");
            webClient.Headers.Add("cache-control", "no-cache");
            webClient.Headers.Add("Bearer", token);

//further down to the call...

var content = JsonConvert.SerializeObject(request).Replace(@"\", @"");
                var jsonResponse = webClient.UploadString($"https://{APIHost}{APIAddress}", content.ToString());
question from:https://stackoverflow.com/questions/65925984/using-webclient-keeps-changing-json-to-text-plain-for-content-type

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...