API Lucee 服务器上的响应文件内容为空
API Response filecontent is Empty on Lucee server
当我调用 Coldfusion 服务器中的 canadaPost api 时,它给出了预期的响应。但是当我在 Lucee 服务器中使用相同的调用时,它会抛出消息失败。两台服务器的响应 header 都是 "Oracle-iPlanet-Web-Server/7.0"。但是响应 mimetype 在 Lucee 服务器中是 "application/octet-stream",在 coldfusion 服务器中是 "application/vnd.cpc.ship.rate-v3+xml"。
这是问题的原因吗?请对此提出您的建议。
这是我的代码:
<cfset local.url = "https://ct.soa-gw.canadapost.ca/rs/ship/price">
<cfhttp url="#local.url#" method="post" result="httpResponse" username="#variables.username#" password="#variables.password#">
<cfhttpparam type="header" name="Accept" value="application/vnd.cpc.ship.rate-v3+xml"/>
<cfhttpparam type="xml" value="#trim(xmlRequest)#"/>
<cfhttpparam type="header" name="Content-type" value="application/vnd.cpc.ship.rate-v3+xml">
</cfhttp>
附上在 Lucee 服务器上截取的屏幕截图:
谢谢
Lucee(以及之前的 Railo)中存在一个错误,即在使用 SSL 时不会发送 <cfhttp>
中指定的用户名和密码属性。
要解决此问题,您可以使用 <cfhttpparam>
发送授权 header,如下所示:
<cfhttp url="#local.url#" method="post" result="httpResponse">
<cfhttpparam type="header" name="Accept" value="application/vnd.cpc.ship.rate-v3+xml"/>
<cfhttpparam type="xml" value="#trim(xmlRequest)#"/>
<cfhttpparam type="header" name="Content-type" value="application/vnd.cpc.ship.rate-v3+xml">
<cfhttpparam type="header" name="Authorization" value="Basic #ToBase64( variables.username & ':' & variables.password )#">
</cfhttp>
最后我通过将 cfhttpparam 类型 "xml" 更改为 "body" 获得了文件内容值。
我的修复:
<cfset local.url = "https://ct.soa-gw.canadapost.ca/rs/ship/price">
<cfhttp url="#local.url#" method="post" result="httpResponse" username="#variables.username#" password="#variables.password#">
<cfhttpparam type="header" name="Accept" value="application/vnd.cpc.ship.rate-v3+xml"/>
<cfhttpparam type="body" value="#trim(xmlRequest)#"/>
<cfhttpparam type="header" name="Content-type" value="application/vnd.cpc.ship.rate-v3+xml">
</cfhttp>
谢谢 guyz..
当我调用 Coldfusion 服务器中的 canadaPost api 时,它给出了预期的响应。但是当我在 Lucee 服务器中使用相同的调用时,它会抛出消息失败。两台服务器的响应 header 都是 "Oracle-iPlanet-Web-Server/7.0"。但是响应 mimetype 在 Lucee 服务器中是 "application/octet-stream",在 coldfusion 服务器中是 "application/vnd.cpc.ship.rate-v3+xml"。
这是问题的原因吗?请对此提出您的建议。
这是我的代码:
<cfset local.url = "https://ct.soa-gw.canadapost.ca/rs/ship/price">
<cfhttp url="#local.url#" method="post" result="httpResponse" username="#variables.username#" password="#variables.password#">
<cfhttpparam type="header" name="Accept" value="application/vnd.cpc.ship.rate-v3+xml"/>
<cfhttpparam type="xml" value="#trim(xmlRequest)#"/>
<cfhttpparam type="header" name="Content-type" value="application/vnd.cpc.ship.rate-v3+xml">
</cfhttp>
附上在 Lucee 服务器上截取的屏幕截图:
谢谢
Lucee(以及之前的 Railo)中存在一个错误,即在使用 SSL 时不会发送 <cfhttp>
中指定的用户名和密码属性。
要解决此问题,您可以使用 <cfhttpparam>
发送授权 header,如下所示:
<cfhttp url="#local.url#" method="post" result="httpResponse">
<cfhttpparam type="header" name="Accept" value="application/vnd.cpc.ship.rate-v3+xml"/>
<cfhttpparam type="xml" value="#trim(xmlRequest)#"/>
<cfhttpparam type="header" name="Content-type" value="application/vnd.cpc.ship.rate-v3+xml">
<cfhttpparam type="header" name="Authorization" value="Basic #ToBase64( variables.username & ':' & variables.password )#">
</cfhttp>
最后我通过将 cfhttpparam 类型 "xml" 更改为 "body" 获得了文件内容值。
我的修复:
<cfset local.url = "https://ct.soa-gw.canadapost.ca/rs/ship/price">
<cfhttp url="#local.url#" method="post" result="httpResponse" username="#variables.username#" password="#variables.password#">
<cfhttpparam type="header" name="Accept" value="application/vnd.cpc.ship.rate-v3+xml"/>
<cfhttpparam type="body" value="#trim(xmlRequest)#"/>
<cfhttpparam type="header" name="Content-type" value="application/vnd.cpc.ship.rate-v3+xml">
</cfhttp>
谢谢 guyz..