询问者
获取 aspx 网站 文件原名

问题
全部回复
-
请给出完整的代码——你用WebRequest和WebResponse来做的吗?
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats -
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(pUrl); HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); for (int i = 0; i < myHttpWebResponse.Headers.Count; ++i) Console.WriteLine("Header Name:{0}, Value :{1}", myHttpWebResponse.Headers.Keys[i], myHttpWebResponse.Headers[i]); myHttpWebResponse.Close();
输出的信息如下,没有 Content-Disposition :
Header Name:Cache-Control, Value :privateHeader Name:Content-Type, Value :image/gif
Header Name:Set-Cookie, Value :.ASPXANONYMOUS=iJOG6vBvzgEkAAAAM2E5YmZmN2ItZTk2OC00MjBjLWJmZjgtYzQ0YTliODcyYzdhTewXLP6UnKbwfD78_r4XugAAAAA1; expires=Sun, 23-Jun-2013 09:06:15 GMT; path=/; HttpOnly,ASP.NET_SessionId=o5uzge45or3hbmuzoo4d0x55; path=/; HttpOnly,AD_RS_COOKIE=20080916; expires=Mon, 15-Apr-2013 22:26:16 GMT; path=/;
Header Name:Server, Value :Microsoft-IIS/7.5
Header Name:X-AspNet-Version, Value :2.0.50727
Header Name:X-Powered-By, Value :ASP.NET
Header Name:Date, Value :Sun, 14 Apr 2013 22:26:15 GMT
Header Name:Content-Length, Value :1870
-
using (WebClient client = new WebClient()) { using (Stream rawStream = client.OpenRead(pUrl)) { string contentDisposition = client.ResponseHeaders["content-disposition"]; if (!string.IsNullOrEmpty(contentDisposition)) { string lookFor = "filename="; int index = contentDisposition.IndexOf(lookFor, StringComparison.CurrentCultureIgnoreCase); if (index >= 0) { string fileName = contentDisposition.Substring(index + lookFor.Length); Console.WriteLine(fileName); } } else Console.WriteLine("null"); } }
得到的结果也是空值 -