我突然说System.Net.WebException : The request was abborted: The Request was canceled. ---> System.NotSupportedException : This method is not supported by this class
这个奇怪的错误。我不知道为什么会发生因为它曾经工作得很好。
我尝试在线搜索,但没有找到有关此事的帮助。以下是我正在使用的方法,我已经指出了发出错误的行。
//get column heading names from formatted text file
public string getFTextColumnHead(string serverURL, string userName, string password, int headRow,
string filePath, string reqFrom)
{
string line = "";
//initialize WebClient object
WebClient client = new WebClient();
//if the request is for web
if (reqFrom == "web")
{
//send web request to retreive the data from the url
HttpWebRequest req = (HttpWebRequest) WebRequest.Create(serverURL);
//parse credentials to the web server to authenticate
client.Credentials = new NetworkCredential(userName, password);
//Grab Data from the web server and save to the given path
client.DownloadFile(new Uri(serverURL), filePath);//<---exception occurs here
}
//initialize input output stream and open the downloaded file
StreamReader file = new StreamReader(filePath);
//loop through the rows of the file until the column heading row is reached
for (int i = 0; i < headRow; i++)
{
//read the line
line = file.ReadLine();
}
//dipoase the client
client.Dispose();
//return the column heading string
return line;
}
谢谢你们。我正在关闭这个项目的截止日期。所有这一切都发生在最后一刻。非常感谢帮助:)
P.S。我安装了Resharper
来查看代码。但是我并没有对这个特殊的班级做出任何改变:)。