0

我编写了一个简单的应用程序来测试一个 RESTful API(由一个会计应用程序提供)。我在 Firefox 中安装了“Poster”来测试“GET 和 POST”XML,并且 API 的行为正常。我编写了一个简单的“GET”测试页面来从测试 CF8 应用程序中调用 API,并且 API 返回了我预期的结果。我无法从测试 CF8 应用程序中 POST。

我已将以下内容插入到我的 application.cfm 中:

<!--- fix for HTTPS connection failures --->
<cfif NOT isDefined("Application.sslfix")>
    <cfset objSecurity = createObject("java", "java.security.Security") />
    <cfset objSecurity.removeProvider("JsafeJCE") />
    <cfset Application.sslfix = true />
</cfif>

这是失败的代码:

<cfprocessingdirective suppressWhiteSpace = "Yes">    
    <cfxml variable="customerxml">
        <?xml version="1.0" encoding="UTF­8" standalone="yes"?>
        <dataentry>
            <interface name="Customer Edit"></interface>
            <entity>
                <attribute name="Customer Code">REP003</attribute>
                <attribute name="Customer Name">Repsol3</attribute>
                <attribute name="Address Line 1">El House</attribute>
                <attribute name="Address Line 2">El Street</attribute>
                <attribute name="Address Line 3">El Town</attribute>
            </entity>
        </dataentry>
    </cfxml>
</cfprocessingdirective>

<cfhttp 
    method="post" 
    url="https://***/wsapi/1.1/dataentry/"
    username="***"
    password="***"
    charset="utf-8">
    <cfhttpparam type="header" name="Accept-Encoding" value="*" />
    <cfhttpparam type="header" name="TE" value="deflate;q=0" />
    <cfhttpparam type="header" name="Content-Type" value="application/xml" />
    <cfhttpparam name="XML_Test" type="xml" value="#customerxml#">
</cfhttp> 

有很多关于这个主题的文章,我已经尝试了大多数东西,但有些帖子甚至比我的 CF 版本更老!任何最新的帮助表示赞赏。

4

2 回答 2

2

从评论中

我在收到连接失败时尝试的第一件事<cfhttp>是验证您是否可以使用浏览器从您的 ColdFusion 服务器导航到该 URL 。如果该请求不起作用,那么它也不会从 ColdFusion 调用中起作用。在继续之前先解决该问题。

使用 SSL (HTTPS) 连接到安全站点时的另一个常见问题是证书不受信任或 ColdFusion (Java) 不知道。在这些情况下,您需要将他们的证书导入到用于 ColdFusion 的 Java 密钥库中。

于 2014-10-02T17:23:32.593 回答
0

这是关于如何安装 Java 库未安装的自签名证书或其他 ssl 证书的一个很好的分步说明。

http://www.coldfusioncookbook.com/entries/How-Do-I-Consume-SSL-Encrypted-Content-with-CFHTTP.html

已经帮了我1000次。马特

于 2014-10-02T23:53:32.277 回答