对API的ColdFusion SOAP调用
我正在关注RegOnline的开发者页面,以设置对服务器的API调用。它们提供了各种如何握手的示例(PHP、C#、JS、SOAP),最后一个示例提供了如何将API令牌作为方法调用的一部分的最差示例 我试图调用他们的方法,这个调用必须包括我生成的API令牌。然而,基于他们的SOAP示例,我只能猜测如何包含令牌的值。以下是他们的例子:对API的ColdFusion SOAP调用,soap,coldfusion,coldfusion-10,Soap,Coldfusion,Coldfusion 10,我正在关注RegOnline的开发者页面,以设置对服务器的API调用。它们提供了各种如何握手的示例(PHP、C#、JS、SOAP),最后一个示例提供了如何将API令牌作为方法调用的一部分的最差示例 我试图调用他们的方法,这个调用必须包括我生成的API令牌。然而,基于他们的SOAP示例,我只能猜测如何包含令牌的值。以下是他们的例子: <s:complexType name="TokenHeader"> <s:sequence> <s:element mi
<s:complexType name="TokenHeader">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="APIToken" type="s:string"/>
</s:sequence>
<s:anyAttribute/>
</s:complexType>
页面上的其他示例都有完整版本,明确显示了在必要时可以硬编码令牌的位置。我承认我目前对SOAP的了解很少,所以在这个例子中我可能遗漏了一些东西
下面是我调用该方法的尝试。它只会吐出一页他们的文档和200 OK状态,这是不对的
<cfset apiToken = "xxxxx" />
<cfset eventID = "xxxxxx" />
<cfsavecontent variable="soapBody">
<cfoutput>
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<GetEvent xmlns="http://www.regonline.com/api">
<eventID>#eventID#</eventID>
</GetEvent>
</s:Body>
</s:Envelope>
<s:complexType name="TokenHeader">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="APIToken" type="s:string">
#apiToken#
</s:element>
</s:sequence>
<s:anyAttribute/>
</s:complexType>
</cfoutput>
</cfsavecontent>
<cfhttp url="https://www.regonline.com/api" method="get" result="theCFHTTP" redirect="true">
<cfhttpparam type="HEADER" name="Content-Type" value="text/xml; charset=utf-8">
<cfhttpparam type="HEADER" name="Accept" value="application/soap+xml, multipart/related, text/*">
<cfhttpparam type="HEADER" name="User-Agent" value="Axis/1.1">
<cfhttpparam type="HEADER" name="Cache-Control" value="no-cache">
<cfhttpparam type="HEADER" name="Pragma" value="no-cache">
<cfhttpparam type="HEADER" name="SOAPAction" value="https://www.regonline.com/api/default.asmx/GetEvent">
<cfhttpparam type="HEADER" name="Content-Length" value="#len(soapBody)#">
<cfhttpparam type="xml" name="body" value="#soapBody#">
</cfhttp>
<cfdump var="#theCFHTTP#">
#事件#
#apiToken#
您的SOAP请求格式错误。所有SOAP请求都应该在SOAP信封中。以下是在中为getEvent请求创建的模板
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:api="http://www.regonline.com/api">
<soapenv:Header>
<api:TokenHeader>
<!--Optional:-->
<api:APIToken>?</api:APIToken>
</api:TokenHeader>
</soapenv:Header>
<soapenv:Body>
<api:GetEvent>
<api:eventID>?</api:eventID>
</api:GetEvent>
</soapenv:Body>
</soapenv:Envelope>
?
?
对于呼叫本身,您可能需要尝试post over get,但我不确定这一点。我认为您可能需要更新的一件事是SOAPAction。在SoapUI中的测试调用中,头中的操作是
http://www.regonline.com/api/GetEvent
。尽管它可能是双向的。这不是你想做的。使用SOAP调用,只需遵循文档()中提供的XML即可
因此,在特定情况下,您希望将CSSAVECONTENT
变量soapBody
替换为以下内容:
<cfsavecontent variable="soapBody">
<cfoutput>
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<TokenHeader xmlns="http://www.regonline.com/api">
<APIToken>#apiToken#</APIToken>
</TokenHeader>
</soap:Header>
<soap:Body>
<GetEvent xmlns="http://www.regonline.com/api">
<eventID>#eventID#</eventID>
</GetEvent>
</soap:Body>
</soap:Envelope>
</cfoutput>
</cfsavecontent>
#apiToken#
#事件#
看看你得到了什么。我不知道我怎么会错过你提供的文档URL,但这帮了大忙。输出仍然只显示文档页面内容,但该问题将需要另一篇文章。您的格式正确,但某些标记不正确;然而,对这些问题的猜测是正确的。