2016-05-04 11 views
-1

私はPDFビューアページのHTTPヘッダーを取得しようとしていますが、pdfファイルを入手して読むことができます。私は次のコード行を使用しています:現在のセレクションのdrive.urlでhttpヘッダーを取得するには?

var disposition= System.Web.HttpContext.Current.Request.Headers["Content-Disposition"]; 

をしかし、現在はnullです:

using (WebClient client = new WebClient()){ 
client.OpenRead(driver.Url); 
string header_contentDisposition = client.ResponseHeaders["content-disposition"]; 
string filename = new ContentDisposition(header_contentDisposition).FileName; 
} 

をしかし、サーバがソースを見つけていない、私もこれをしようとしています。より良いhttpヘッダーを理解するためのアドバイスやリンクをお願いします。前もって感謝します。

+0

[セレンでリクエストヘッダを設定]の可能な複製を(http://stackoverflow.com/questions/15645093/setting-request -headers-in-Selenium) –

答えて

-1

あなたはC#でwebdriverをを使用して他の方法でファイルを取得することができます:

public string DownloadFile(string url, string filename) 
{ 
    var dirToSave = "C:/Directory/Test"; 

    if (!Directory.Exists(dirToSave)) 
     Directory.CreateDirectory(dirToSave); 

    var localPath = String.Format("{0}\\{1}", dirToSave, filename); 

    var client = new WebClient(); 
    client.Headers[HttpRequestHeader.Cookie] = CookieString(); 

    try 
    { client.DownloadFile(GetAbsoluteUrl(url), localPath); } 
    catch (Exception ex) 
    { Assert.Fail("Error to download the file: " + ex); } 


    return localPath; 
} 
関連する問題