我突然说这个奇怪的错误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;
}
感谢你们。我即将结束这个项目的最后期限。这一切都发生在最后一刻。非常感谢您的帮助:)
PS我安装Resharper
以查看代码。但我没有对这个特定的班级做出任何建议:)。