问题
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?
回答1:
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() : "">
回答2:
It is/was probably caused by missing certificate on your CF server for the https connection (keystore file: cf11/jre/lib/security/cacerts).
来源:https://stackoverflow.com/questions/35427380/cfhttp-read-data-from-url-transferring-in-chunks