我的httpwebrequests有時會出現奇怪的錯誤。httpwebrequest編碼錯誤
錯誤即時得到:
ArgumentException was unhandled by user code
'' is not a supported encoding name.
代碼我運行:
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Timeout = 3000;
request.ReadWriteTimeout = 3000;
request.Proxy = new WebProxy(p.ToString(), true);
response = (HttpWebResponse)request.GetResponse();
Encoding responseEncoding = Encoding.GetEncoding(response.CharacterSet);
using (StreamReader sr = new StreamReader(response.GetResponseStream(), responseEncoding))
{
if (response.StatusCode == HttpStatusCode.OK)
{
// do stuff
}
}
}
catch (WebException wexc1)
{
if (wexc1.Status == WebExceptionStatus.ProtocolError)
{
return false;
}
}
finally
{
if (response != null)
response.Close();
}
它doesent happend所有的時間它像1出500的請求。它感覺就像代碼無法確定實際的編碼..但我將如何處理這個?
該錯誤當前使應用程序崩潰
完美! UTF-8工作:)謝謝一堆 – Jacqueline