請告訴我如何將標題設置爲webclient? 我試試這個WP8上的WebClient頭文件
WebClient webClient = new WebClient();
webClient.Headers["Content-Encoding"] = "gzip";
webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
webClient.DownloadStringAsync(new Uri("..."));
但我收到的異常:System.Reflection.TargetInvocationException。 「操作過程中發生異常,導致結果無效。請檢查InnerException以瞭解異常詳細信息。」
- InnerException {System.Net.WebException:在WebClient請求期間發生異常。 ---> System.Net.ProtocolViolationException:使用此方法的請求不能有請求主體。在System.Net的System.Net.WebClient.GetWebResponse(WebRequest請求,IAsyncResult結果)System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod,對象狀態) .WebClient.DownloadBitsResponseCallback(IAsyncResult的結果) ---內部異常堆棧跟蹤---} System.Exception的{System.Net.WebException}
你可以發佈InnerException嗎? – Raymen
@ Raymond我編輯我的帖子 – Nikita
作爲一個快速解決方案,只是不要使用'WebClient',而是使用'HttpClient'。 –