0

I'm trying to get Http headers of a PDF viewer page, for can get the pdf file and read it. I'm using the following lines of code:

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

But the server is not finding the source, I'm trying this too:

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

But Current is null. Any advises or links for understand better http headers, please. Thanks in advance.

UserEsp
  • 415
  • 1
  • 7
  • 29
  • Possible duplicate of [setting request headers in selenium](http://stackoverflow.com/questions/15645093/setting-request-headers-in-selenium) – timbre timbre May 04 '16 at 16:14

1 Answers1

-2

You can get the file by other way using the webdriver in C#:

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;
}
Striter Alfa
  • 1,577
  • 1
  • 14
  • 31