我正在尝试将API调用编码为在线测试公司。他们提供了PHP和cURL的示例调用,我需要使用来在ColdFusion 11中实现该调用<CFHTTP>。到目前为止,我的尝试失败了。我从他们的服务器/ API得到的唯一响应是:
Statuscode =“连接失败。状态代码不可用。”
和
ErrorDetail =“ I / O异常:握手期间远程主机关闭了连接”。
如果工作正常,我将获得一个JSON字符串,详细说明计算的分数。请注意,出于安全原因,在下面的代码中,我更改了一些值,但它是原始代码。任何建议或意见,将不胜感激,谢谢。
这是ColdFusion / cfhttp代码:
<cfoutput>
<cfset sdata = [
{
"customerid" = "ACompany",
"studentid" = "test",
"form" = "X",
"age" = "18.10",
"norms" = "grade",
"grade" = "2"
},
{
"scores" = [
{"subtest"="math","score"="34"},
{"score"="23","subtest"="lang"},
{"score"="402","subtest"="rcomp"}
]
}
]>
<!--- create JSON string for request --->
<cfset jsdata = serializeJSON(sdata)>
<!--- make the call --->
<cfhttp method="Get" url="https://www.APIwebsite.php" timeout="10" result="varx">
<cfhttpparam type="header" name="Content-Type" value = "application/json; charset=utf-8"/> …Run Code Online (Sandbox Code Playgroud)