How to automatically click "do you want to open or save?".

I am wondering if there is a C # or selenium solution for the following:

enter image description here

I use selenium to download a file from a web server.

Unfortunately, in IE9 there is no way to disable this pop-up screen.

Is there a solution in C # for pushing the SAVE button?

+5
source share
1 answer

Client

WebClient client = new WebClient();
byte[] file = client.DownloadData("http://domain.com/default.aspx");
File.WriteAllBytes("helloworld.txt", file);

Server

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        using (MemoryStream memory = new MemoryStream())
        using (StreamWriter writer = new StreamWriter(memory))
        {
            // The bytes written can be anything, does not have to be text
            writer.WriteLine("hello, world");
            writer.Flush();
            Response.BinaryWrite(memory.ToArray());
        }

        Response.AddHeader("Content-Disposition", "Attachment; filename=helloworld.txt");
        Response.AddHeader("Content-Type", "application/octet-stream");
        Response.End();
    }
}

, , ! , , , WebClient.DownloadData() . , . , .


:

, , .

- HTTP- . , . - HTTP-GET , - HTML. , , Content-Type Text/HTML. , , MIME, Content-Type text/plain, , . /XML XML .. , MIME .

" " , Content-Disposition: Attachment. , .

WebClient/HttpWebRequest, , , , , MIME/HTTP-, . Content-Disposition ( ) Open Save.

+3

All Articles