CFHTTP - Read data from URL transferring in chunks

微笑、不失礼 提交于 2019-12-14 01:24:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!