This is a migrated thread and some comments may be shown as answers.

Get PDF from response

5 Answers 269 Views
FiddlerCore
This is a migrated thread and some comments may be shown as answers.
Maikel
Top achievements
Rank 1
Maikel asked on 07 Oct 2014, 03:00 PM
Hello.

I have a, I hope, simple request. 

I want to get a PDF from a response. But somehow I can't get the right response.
The MIME TYPE = "application/pdf", but when I try to get the PDF uit. I am never able to open the PDF.
It is from a HTTPS response but I do have the right certificate. Also, decode always returns false.

Could someone explain the right way to extract a file from a response?

PS: I use fiddlercore with C# 

5 Answers, 1 is accepted

Sort by
0
Eric Lawrence
Telerik team
answered on 07 Oct 2014, 09:01 PM
When asking what is wrong with your code, it is helpful to provide that code so that others might see what is wrong with it.

Generally speaking, you want to call oSession.utilDecodeResponse() on the session containing the desired traffic, then interact with the oSession.responseBodyBytes array of bytes.

Regards,
Eric Lawrence
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Maikel
Top achievements
Rank 1
answered on 08 Oct 2014, 11:44 AM
I am using  this event: void FiddlerApplication_ResponseHeadersAvailable(Session oSession)

Then, when I detect the MIME = "application/pdf"
I call this event:
if (oSession.oResponse.MIMEType == "application/pdf")
           {
               var isChecked = Task.Factory.StartNew(() => Fiddler.FiddlerApplication.AfterSessionComplete += delegate(Session oS)
                   {
                       if (oS.oResponse.MIMEType == "application/pdf")
                       {
                                   oS.utilDecodeResponse();
                                   SaveToOutput(oS.responseBodyBytes);
                       }
                   };
           }
0
Eric Lawrence
Telerik team
answered on 08 Oct 2014, 01:25 PM
The ResponseHeadersAvailable event runs when the response headers are available. When the headers are received, the body hasn't been received yet, so your attempts to manipulate the body are doomed to failure.

Move your code to the BeforeResponse handler instead.

Regards,
Eric Lawrence
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Maikel
Top achievements
Rank 1
answered on 09 Oct 2014, 09:39 AM
That did indeed the trick, Thank you.

Then there is one more question. 

Can I disable or cancel the file download dialog with Fiddlercore?
As I already extracted the file. I do not want to get the popup.
0
Eric Lawrence
Telerik team
answered on 09 Oct 2014, 04:07 PM

Fiddler/FiddlerCore don't have any awareness of your browser or its dialogs; they only see the traffic itself. In some cases, you could prevent the download dialog from appearing by (after you've already copied the responseBodyBytes wherever you wanted) replacing the HTTP response with an HTTP/204 "No content" reply, or a HTTP/200 reply with a simple HTML page indicating that the document was intercepted by an intermediary. (See the oSession.oRequest.FailSession method).

However, this may have unexpected behavior depending on how the target site attempted to kick off the file download. For instance, if it used the download attribute, the user would see a prompt to save your "no content" response.

Regards,

Eric Lawrence
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
FiddlerCore
Asked by
Maikel
Top achievements
Rank 1
Answers by
Eric Lawrence
Telerik team
Maikel
Top achievements
Rank 1
Share this question
or