SimonGSW wrote I am trying to get PDF content using CFHTTP from the following link: https://policy.ucop.edu/doc/3220479/BFB-BUS-38. It works in browser, but CFHTTP returns following: | ErrorDetail | I/O Exception: null | | Filecontent | Connection Failure | | Header | [empty string] | | Mimetype | Unable to determine MIME type of file. | | Responseheader | | | Statuscode | Connection Failure. Status code unavailable. | | Text | YES |
My CF code is: <cfhttp method="get" url="https://policy.ucop.edu/doc/3220479/BFB-BUS-38" timeout="50" result="test"></cfhttp> <cfdump var="#test#" label="test"> CF Server is CF11 developer edition, version 11,0,15,311399. Looking at Response headers in browser, I noticed that Transfer-Encoding: chunked and Content-Length is missing(Server Apache). Is there problem with CFHTTP and Transfer-Encoding: chunked? Any ideas on how to make it work? |
Hi SimonGSW, I have an idea on how to make it work. The site may be expecting you to pass it some parameters. To know which parameters to pass, open any URL in the browser and press F12 on your keyboard to open the Developer Tools screen.
Then, with the Developer Tools still visible, open https://policy.ucop.edu/doc/3220479/BFB-BUS-38. You should see the PDF file as expected.
Now, click on the Network tab in Developer Tools. Copy all the request headers and use them as HTTP parameters in your cfhttp call. In your cfhttp tag, change the method from Get to Post. Also add the attributes, Port and Getasbinary. The result should be something like this:
<cfhttp method="post" url="https://policy.ucop.edu/doc/3220479/BFB-BUS-38" timeout="50" port="443" getasbinary="yes">
<cfhttpparam type="header" name="Accept" value="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" />
<cfhttpparam type="header" name="Accept-Encoding" value="gzip, deflate, br" />
<cfhttpparam type="header" name="Accept-Language" value="en-US,en;q=0.5" />
<cfhttpparam type="header" name="Connection" value="keep-alive" />
<cfhttpparam type="header" name="Host" value="policy.ucop.edu" />
<cfhttpparam type="header" name="Upgrade-Insecure-Requests" value="1" />
<cfhttpparam type="header" name="Cookie" value="PHPSESSID=40kdc682uolbvouq7ufv7t81s3; NSC_qpmjdz=ffffffff8338570445525d5f4f58455e445a4a423660" />
</cfhttp>
<cfcontent type="application/pdf" variable="#cfhttp.filecontent#">