我使用.NET 3.5中的WebClient類下載文件。我想確保在服務器端,所請求的文件似乎是用IE客戶端下載的。我需要改變什麼?使用WebClient類模擬來自IE客戶端的請求?
我是否簡單地將IE生成的頭信息複製到WebClient對象的Header屬性?還有什麼我需要做的?
謝謝
我使用.NET 3.5中的WebClient類下載文件。我想確保在服務器端,所請求的文件似乎是用IE客戶端下載的。我需要改變什麼?使用WebClient類模擬來自IE客戶端的請求?
我是否簡單地將IE生成的頭信息複製到WebClient對象的Header屬性?還有什麼我需要做的?
謝謝
根據您的需要,只需設置用戶代理標頭可能就足夠了。有一個例子:http://msdn.microsoft.com/en-us/library/system.net.webclient(VS.80).aspx
簡短的回答是肯定的。
以下代碼提供了完整的標題信息,只需在瀏覽器中運行它即可,您將完成設置。
<html>
<body>
<script type="text/javascript">
var x = navigator;
document.write("CodeName=" + x.appCodeName);
document.write("<br />");
document.write("MinorVersion=" + x.appMinorVersion);
document.write("<br />");
document.write("Name=" + x.appName);
document.write("<br />");
document.write("Version=" + x.appVersion);
document.write("<br />");
document.write("CookieEnabled=" + x.cookieEnabled);
document.write("<br />");
document.write("CPUClass=" + x.cpuClass);
document.write("<br />");
document.write("OnLine=" + x.onLine);
document.write("<br />");
document.write("Platform=" + x.platform);
document.write("<br />");
document.write("UA=" + x.userAgent);
document.write("<br />");
document.write("BrowserLanguage=" + x.browserLanguage);
document.write("<br />");
document.write("SystemLanguage=" + x.systemLanguage);
document.write("<br />");
document.write("UserLanguage=" + x.userLanguage);
</script>
</body>
</html>