string serverPath="http://127.0.0.1/file/order?id=10";
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(serverPath);
httpWebRequest.Headers.Add("Translate:f");
httpWebRequest.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream stream = null;
stream = httpWebResponse.GetResponseStream();
int fileSize = (int)httpWebResponse.ContentLength;
byte[] buffer = new byte[fileSize];
FileStream fileStream = File.Open(localDownLoadPath, System.IO.FileMode.Create, System.IO.FileAccess.Write);
int length = stream.Read(buffer, 0, fileSize);
long total = length;
while (length > 0)
{
fileStream.Write(buffer, 0, length);
length = stream.Read(buffer, 0, fileSize);
total += length;
}
fileStream.Close();
网址采用了伪静态,下载不了文件,不知有何办法?
webclient.down,......试试
WebClient client = new WebClient();
client.DownloadString(URL);