1.c# 關於Content與ContentType之前的對應關系:
MultipartFormDataContent=》multipart/form-data
FormUrlEncodedContent=》application/x-www-form-urlencoded
StringContent=》application/json等
StreamContent=》binary
2.c#中request和response的編碼和請求類型設置
// dict為Dictionary<string, string>,from類型數據
HttpContent httpContent = new FormUrlEncodedContent(dict);
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded"); httpContent.Headers.ContentType.CharSet = "GBK"; var response = _HttpClient.PostAsync(url, httpContent).Result; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); response.Content.Headers.ContentType.CharSet = "GBK";
// 接口返回數據
responseJson = response.Content.ReadAsStringAsync().Result;
參考:https://www.cnblogs.com/jerryqi/p/11592676.html