我尝试使用HttpURLConnection,Content-Disposition获取下载的文件名,但我总是得到空值。
在我的代码下面:
URL url = new URL("http://www.somewebsite.com/emp/Emp_view_rs.aspx?RSID=ezxJzVOJYgZuRiRjmEzZhe==&HighlightWords=.NET%2cASP%2cASP.NET%2cASP%2c.NET%2cASP.NET%2cASP.NET ");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("GET");
conn.setAllowUserInteraction(false);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.connect();
String raw = conn.getHeaderField("Content-Disposition");
System.out.println(raw); **//Always getting raw value as NULL**
if (raw != null && raw.indexOf("=") != -1) {
String[] fileName = raw.split("=");
for(int g=0;g<=fileName.length;g++)
{
System.out.println(fileName[g]);
}
} else {
}