如何通过http下载一个文件并保存到本地
private void getInternetFile(string url)
{
Uri fileUrl = new Uri(url);
// Create a 'FileWebrequest' object with the specified Uri.
WebRequest myWebRequest = (WebRequest)WebRequest.Create(fileUrl);
// Send the 'FileWebRequest' object and wait for response.
WebResponse myWebResponse = (WebResponse)myWebRequest.GetResponse();
// Get the stream object associated with the response object.
FileStream receiveStream = myWebResponse.GetResponseStream();
BinaryReader r = new BinaryReader(receiveStream);
// Release resources of response object.
myWebResponse.Close();
}
以上是我的代码,访问url并保存到本地固定目录下,写不下去,希望哪位能帮帮。