viewpoint-particle

Author Topic: Problems downloading a PDF  (Read 302 times)

bottomleypotts

  • Newbie
  • *
  • Posts: 13
Problems downloading a PDF
« on: May 03, 2018, 12:11:14 pm »
I am having difficulty downloading a PDF. I can only seem to download the first couple of bytes of a 1Mb file. Can anyone tell me what I am doing wrong here? I have loaded fiddler and can see that the entire PDF is retrieved by the request.

Code: Winbatch
o=CreateObject(`MSXML2.XMLHTTP.6.0`)

url=`http://kmmc.in/wp-content/uploads/2014/01/lesson2.pdf`

o.Open(`GET`,url,@FALSE)
o.SetRequestHeader(`User-agent`,`Mozilla/5.0 (Windows NT 10.0; rv:55.0) Gecko/20100101 Firefox/55.0`)
o.SetRequestHeader(`Accept`,`text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8`)

o.Send()
While o.ReadyState!=4
        o.WaitForResponse(1000)
EndWhile

Rc=FilePut(DirScript():`lesson2.pdf`,o.ResponseText)

td

  • Tech Support
  • *****
  • Posts: 2595
    • WinBatch
Re: Problems downloading a PDF
« Reply #1 on: May 03, 2018, 01:38:57 pm »
A pdf document is binary and not text so you need to use a different object method (ResponseBody) and a different technique for writing it to a file (binary buffers).

Code: Winbatch
hBuf = BinaryAllocArray(o.ResponseBody)
BinaryWrite(hBuf, 'c:\temp\dump.pdf')
BinaryFree(hBuf)
 
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


bottomleypotts

  • Newbie
  • *
  • Posts: 13
Re: Problems downloading a PDF
« Reply #2 on: May 03, 2018, 08:16:12 pm »
Thank you!