HTTP request activity saves corrupt pdf file

Hi,
I am trying using the HTTP Request activity (package UiPath.Web.Activities is on version 1.6.0) to download a pdf file. However it gives me a pdf file that cannot be read. I also tried the given workflow with a dummy pdf from Maciej Kuzmicz:

…still the same

What am I doing wrong?
You can find the http request properties in the attached picture.temp|530x500

Hi!

please once check this out.

Regards,
NaNi

Hi,
I receive the following result:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<!-- FileName: index.html
     Language: [en]
-->
<!--Head-->
<head>
  <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  <meta http-equiv="X-UA-Compatible" content="IE=7" />
  <title>McAfee Web Gateway - Notification</title>
  <script src="/mwg-internal/de5fs23hu73ds/files/javascript/sw.js" type="text/javascript" ></script>
  <link rel="stylesheet" href="/mwg-internal/de5fs23hu73ds/files/default/stylesheet.css" />
</head>
<!--/Head-->
<!--Body-->
<body onload="swOnLoad();">
  <table class='bodyTable'>
    <tr>
      <td class='bodyData' background='/mwg-internal/de5fs23hu73ds/files/default/img/bg_body.gif'>
<!--Logo-->
<table class='logoTable'>
  <tr>
    <td class='logoData'>
      <a href='http://de0wc144.hannover-re.grp/index.html'>
        <img src='/mwg-internal/de5fs23hu73ds/files/default/img/logo.gif'></a>
    </td>
  </tr>
</table>
<!--/Logo-->
<!--Contents-->
<!-- FileName: authenticationrequired.html
     Language: [en]
-->
<!--Title-->
<table class='titleTable' background='/mwg-internal/de5fs23hu73ds/files/default/img/bg_navbar.jpg'>
  <tr>
    <td class='titleData'>
      Authentication Required
    </td>
  </tr>
</table>
<!--/Title-->

<!--Content-->
<table class="contentTable">
  <tr>
    <td class="contentData">
      You must be authenticated to access this URL.
    </td>
  </tr>
</table>
    
<script language="javascript" type="text/javascript">
   urlprotocol = "https";
   statuscode=407;

   if(statuscode==401 && urlprotocol == "ftp"){
      document.write("<form name=\"ftpform\" method=\"get\" action=\"\">");
      document.write("<table class=\"contentData\">");
      document.write("<tr><td class=\"contentData\" colspan=2>Please enter your credentials in the form below and click \"Access FTP\" button if your browser doesn't present authentication prompt for FTP sites.</td></tr>");
      document.write("<tr><td class=\"contentData\">Username:</td><td><input type=\"text\" id=\"ftpUsername\" name=\"ftpUsername\" size=40 /></td></tr>");
      document.write("<tr><td class=\"contentData\">Password:</td><td><input type=\"password\" id=\"ftpPassword\" name=\"ftpPassword\" size=40 /></td></tr>");
      document.write("<tr><td class=\"contentData\" colspan=2 align=center><input type=\"button\" onclick=\"redirectToFTP();\" value=\"Access FTP\" /></td></tr>");
      document.write("</table>");
      document.write("</form>");
   }
   
   function redirectToFTP(){
      var username=escape(document.getElementById("ftpUsername").value);
      var password=escape(document.getElementById("ftpPassword").value);
      location.href = "ftp://"+username+":"+password+"@www.eurofound.europa.eu:443"
   }
</script>
<!--/Content-->

<!--Info-->
<table class="infoTable">
  <tr>
    <td class="infoData">
      <b>URL: </b><script type="text/javascript">break_line("https://www.eurofound.europa.eu");</script><br />
    </td>
  </tr>
</table>
<!--/Info-->

<!--/Contents-->
<!--Policy-->
<table class='policyTable'>
  <tr>
    <td class='policyHeading'>
      <hr>
      Company Acceptable Use Policy
    </td>
  </tr>
  <tr>
    <td class='policyData'>
      
    </td>
  </tr>
</table>
<!--/Policy-->
<!--Foot-->
<table class='footTable'>
  <tr>
    <td class='helpDeskData' background='/mwg-internal/de5fs23hu73ds/files/default/img/bg_navbar.jpg'>
      If you have questions, please contact IT Service Desk.<br>IT - Helpdesk<br> Tel.: +49 511 5604-7777  <br> 
    </td>
  </tr>
  <tr>
    <td class='footData'>
      generated <span id="time">2021-10-26 12:02:12</span> by McAfee Web Gateway
      <br />
      RestSharp/106.3.1.0
    </td>
  </tr>
</table>
<!--/Foot-->
      </td>
    </tr>
  </table>
</body>
<!--/Body-->
</html>

Please once check this.

Refards,
NaNi

Hi NaNi,

I checked the workflow that is described there and it works for me. Not sure what it has to do with the authentication problem?

Best,
Fredi

Hi! I think it’s an 407 proxy authentication error. but not sure.

please once change this configuration settings.

Regards,
NaNi

Hi NaNi,
thank you! By using a proxy server for the local area network it worked. However it only worked for the dummy document that does not require an authentication.
For the document that I want to download I get the result status code 401, although I used the right credentials. I put them into the “Simple Authentication” Property of the HTTP Request activity. Is that correct?

Best,
Fredi

Edit: The result status code for the document I want to download is 200. So it seems like I am authorized. However when I try to open the pdf it cannot be loaded.

When I open the downloaded pdf file in notepad it gives me

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >

<html xmlns:v="urn:schemas-microsoft-com:vml" >
      
<head>
<!--[if IE]>
<style>
v\:line { behavior:url(#default#VML); display:inline-block; }
</style >
<![endif]-->

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

<!--  favicon -->
<link rel="shortcut icon" href="../style/mstr/images/favicon.ico" type="image/x-icon" />
<!--  end favicon -->
<title pgn=''>Login. SomePseudoName</title>



<script type="text/javascript" >
    var isQuickSearchEnabled = false;
    // Set common config properties for most applications
    mstrConfig = {
        resolveOnly :'' === 'true',//PAUSE MODE
        isPresentation :'' === 'true',//PRESENTATION MODE
        taskURL: 'TaskProc.aspx',
        taskAdminURL: 'TaskAdmin.aspx',
        thousandsSep: ',',
        decimalSep: '.',
        listSep: ',',
        onMobileDevice: false,
        webVersion: '-1672898783',
        appVersion: '',
        pluginRoot: '../plugins/',
        
        isUsherAuthVisible: true, 
        
        isEdgeModeEnabled: '1' == '1',
        isLinkJSEnabled: '1' == '1',
        allowHTMLOnSelector: '0' == '1',

//AND SO ON...

(these are just some of the top lines since it might contain sensitive data)

When downloading the file manually and open it with text editor you can see the right pdf format:

%PDF-1.4
%âãÏÓ

5 0 obj
<<
/Type /XObject
/Subtype /Image
/Name /Im0
/Width 28
/Height 30
/BitsPerComponent 8
/ColorSpace /DeviceRGB
/Length 90              
/Filter /FlateDecode
>>
stream
xœíÒA
  DQîѼY	A´Ñ Á¿ˆ6=,bNNDt©µY×ÄŽËDæ!¢6ݦÜgÍ>:ç¢,žr÷üqÎGïy«M—)@.“àp3R›%ÌMÚŸ
endstream
endobj

6 0 obj
<<
/Type /XObject
/Subtype /Image
/Name /Im1
/Width 256
/Height 202
/BitsPerComponent 8
/ColorSpace /DeviceRGB
/Length 2127            
/Filter /FlateDecode
>>
stream
xœíÝ]OK Æñïÿ	NÍ!ˆ!ñFRã	$FIR`
â;hEÅ
ž'4‡43ívfvÜíLþ¿+^Êì2óÌîÌvºûç                                                              ˜,_¿~}òäÉÜÜÜÔÔÔ?¸¦ªP…¨ZT9u·þ–ËËËǏ7ºã6¹T9ª"UTÝm…ÈÔ¦<¨;_iPEÑ2£ÃZݱJ‰ª«îC4Ö2ìñ¢êb.
ÍìêTzTiu·e☛›3·Ùlv»Ýº÷kR¨*T!F©ÒêÞ/Äa_ê$üUˆQEª´ºw
qØ'÷º÷hQK¹¢e]PK¹¢e]PK¹¢e]PK¹¢e]PK¹¢e]PK¹
nÙËËˏ?noo?¿¦/ôm®kcÈ®ÂZöôôtsssÕ¢êW{Ÿ«GþsвJ¸üAùuòŸ+ß–Õgè‘ß8d6"ÿ¹òmY
ò‹Ãߧ—U³ÿÕ ÿ¹òmYÍs]ò¯—U³ÿÕ ÿ¹òmÙçÏŸ»ä_/«fÿ«Aþs•_þ;Îþþ¾æ ý³;;;Œýúõ«L™ä?W9òW¯^êGGGÁ%“ÿ\ù¶ìÄÎ/..Æ^˜
Þ+òŸ+ß–ÌëŸÚÜË—/]:æçÏŸÊ'ÿ¹
hÙ	|ÿ«Ýn»„õz t~~î[>ùÏUXËNÔúaÇ!Ù
)|OOä?WÁ-;!ëßNNN¼Âß·¿¿ïµòŸ«¤[öû÷ïŽ×cm^¤k	ÒmÙ^¯7v&^Àk"n-¡X¢-{uuµ»»eþ>÷‰@¢µ„±mÙ7oÞ”ßÞÞžËæ­%Œ•bË~ùò%Jøû\&)Ö\$ײgggkkkóï2H®–à(­–½¸¸xñâEÄð÷¤UKp—PË*¢;;;ÑÃßW<H¨–à%nË^]]žžjD}xx¨QzÀJƒ¯_¿ŽõV«upppttÔét~þüÙëõ.ÿ7jÓä?W±ZVÉWæ766Œ°mmmœœ”ßO^2öÚ¢TÀÖÉ®¢´¬¡Å#oËì¤Ôe’¿½½]rUÒû÷ïïß¿OþóS>ÿ¿ÿÖ¡ulƒ»€†(öiÅ‘†:ŸUÔn·gggÉNJæ_ÞQ¹²¬½w_ØoÓhG»ç»ÅbêìꌍF#n±¨KÉü{ÍI×ÖÖÎÎμÊw_Ø?h}}½xÀ£“‚^³´´Ôl6çççg®é}«êWÅg

‡¼þL¬2ù÷]x/:xºÏ@?|ø~/4dZ R½²²rïÞ½èez1zÌ[pþŒ€pŠfÊ.«ÎÂÊßÝÝÕÅ.­Ûí.//OMM¹$þDÈ3Ñr–
c‚Þ¯:Ì…ÏÏÏÊב߿úÚ³gϦ§§}“?èöíÛ*$³›:âOPþüø|AæFÁÝHÂökÐn{´«e’?HE©À²5ŽIâ›…³Õj•ÿêè¹pðÂ~{Â{||ì8Ôw§Ul´ÚGݼòwÎйðÛ·oŠ:<<4ÊQJgffFÅX£zÌu–ѾÓéô®é}«êW3KȆWþ÷ööb…¿Ï˜‡-ì×ùȸίQʨ#$?v£èezñ¨³ ¡<¸çÿÝ»wqÃßw3îv»aûK”êP£ÆüwîÜÑAÞ½r´K‹‹‹C‹Ò&˜gÀ1ÿš®FOþ
®P؜ھѨŽÛ£†.òèÑ#ßÜjdž‡´¡ÀJÇÄpÉÿ·oߢg~ûÁ‹Œi¯ŽØc/ut
üì. Ñï¤nlþÃ.ÅWckkËØÛåååâð—9Øåhs¥ju+Îÿ_ú¼a,ÆeM죴Æü±º€=ÐæX ‘´‚ü;.l®‘qùteeÅ¢h«¨GéíØW„´ÑhÊÊ¿×ÂæZ´Z-㱯yö§¨
y¬.`O®µÑXmêÊÿÁÁAÝÃXDt||lNn®ÒÇê*ÐbñvXº†æ?`asõŒDëëëF,_«Øo.hÓ±š³ó¯£YÝÑvb¼“µ´´dÄrssÓøg£tkü­6«9P1;ÿqï®ö÷«=›Í¦Ë¡Oû*ßT¬ñ‡Út´ö@µìüםkW½^o𙟟7b9j©CÉ. b¿Ò¦£µaª•nþ Ú«=2¨LP±ÆŸhÓÑÚÕÊ8ÿÅϼî*–üg#Ýüan„uÆ?9I7ÿaó_C@`þ›“tópýs(ß.ÀõÏœ¤›ß÷¿
xuÞÿÊIºù÷Zÿ0–cºþ% éJ7ÿîëß¹tÖ¿e&Ýü¯º­öúˆVqÐŒƒõÏ™I:ÿ.ŸY\\ôª‚.`”†Ï¿¤.éü;~þqccëN
º€Ï?¦îÖ­[FþŸ>}Zw®=¸|þ]GiÇç\ßpé|þ=:§eù¿{÷nB]Àñþ'êÑÏÜÿ$jb{”–v»=øÜÿJs¯#¶&¼£>>Ïý¯òðéÓ§ºó[Öìì¬qÛsîw>¬;ÂeÙceîG:xê€Vw„Ki4ö3¹¸ÿ9©¤~˜žž¶<óü¸Ó\@ÓaÍøì‹¢IÐÁÙ~  Ï?xþÀóO?×Sãâç_3É                                                                     0áþEêÉ
endstream
endobj

//AND SO ON.....

Since the authentication is not a problem anymore there seems to be an issue with the encoding/bodyformat (?) of the HTTP request activity. Here you can see the properties set:


Package version of UiPath.WebAPI.Activities is 1.7.0

Hi @FJJJ

As a simple sanity check, does the exact same API call work in Postman (or other tool of your choice)?

Hi @loginerror and thank you for the advice. I checked with postman and got the same result. I will get back to my colleague, who gave me the link.

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.