Get PDF from response

6 posts, 0 answers
  1. Maikel
    Maikel avatar
    3 posts
    Member since:
    Oct 2014

    Posted 07 Oct 2014 Link to this post

    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# 
  2. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 07 Oct 2014 Link to this post

    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.

     
  3. Maikel
    Maikel avatar
    3 posts
    Member since:
    Oct 2014

    Posted 08 Oct 2014 in reply to Eric Lawrence Link to this post

    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);
                           }
                       };
               }
  4. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 08 Oct 2014 Link to this post

    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.

     
  5. Maikel
    Maikel avatar
    3 posts
    Member since:
    Oct 2014

    Posted 09 Oct 2014 in reply to Eric Lawrence Link to this post

    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.
  6. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 09 Oct 2014 Link to this post

    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.

     
Back to Top