Where is the PDF in a browser response, where Content-Type is application/pdf - WebView2

Viewed 46

Whilst I am using the WebView2 I think this is a more general browser response type question.

I would like to read the response and save it to a file when it is a pdf. For example if you use this test page https://demo.borland.com/testsite/download_testpage.php with No content disposition.

I have the following code.

private async void CoreWebView2_WebResourceResponseReceived(object sender, CoreWebView2WebResourceResponseReceivedEventArgs e)
{
    if (e.Response != null && e.Response.Headers.Contains("Content-Type"))
    {
        if (e.Response.Headers.GetHeader("Content-Type") == @"application/pdf")
        {  
            var stream = await e.Response.GetContentAsync();
            byte[] bytes = new byte[stream.Length];
            stream.Read(bytes, 0, (int)stream.Length);
            string data = Encoding.UTF8.GetString(bytes);
        }
    }
}

I can see that the Content-Type is correct but the response content is text as follows.

<!doctype html><embed name='9B01CF57122245EB36A661DEBDAFF2A2' style='position:absolute; left: 0; top: 0;'width='100%' height='100%' src='about:blank' type='application/pdf' internalid='9B01CF57122245EB36A661DEBDAFF2A2'>

When I look at network logs in chrome (where chrome is set to open pdfs) I also see that the response is this html.

Where is the pdf in the response content?

0 Answers
Related