Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CFHTTP - Read data from URL transferring in chunks

I am trying to get a file from a URL using cfhttp but it seems that the provider is sending the data in chunks.

<cfhttp
    method="get"
    url="https://www.test.com/somefile.xml">
</cfhttp>

The response header is having Transfer-Encoding as chunked and is missing Content-Length. Also, the statusCode is 200 Ok but the FileContent is showing "Connection Failure".

Any suggestions?

like image 746
Beginner Avatar asked Jul 15 '26 05:07

Beginner


1 Answers

Finally, I used java.net.URL to get this working:

<cfset local.objURL = createObject(
                          "java"
                        , "java.net.URL"
                      ).init( javaCast( "string" , "https://test.com/abc.xml" ) )>

<!--- Input Stream --->
<cfset local.inputStream = local.objURL.openStream()>

<!--- Get Content --->
<cfset local.objScanner = createObject(
                              "java"
                            , "java.util.Scanner"
                          ).init( local.inputStream ).useDelimiter( "\\A" )>
<cfset local.fileContent = local.objScanner.hasNext() ? local.objScanner.next() : "">
like image 126
Beginner Avatar answered Jul 18 '26 13:07

Beginner