我有时在我的 httpwebrequests 上遇到一个奇怪的错误。
我得到的错误:
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();
}
它不会一直发生,就像 500 个请求中的 1 个一样。感觉就像代码无法确定实际编码..但我将如何处理呢?
该错误当前使应用程序崩溃