我正在尝试使用Google API创建一个caledar,它只返回我帐户中的日历列表,就像我发送了一个GET请求一样。这是我的代码:
<cfxml variable="locals.xml">
<cfoutput>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005" xmlns:gCal="http://schemas.google.com/gCal/2005">
<title type="text">#arguments.argTitle#</title>
<summary type="text">#arguments.argSummary#</summary>
<cfif len(arguments.argTimezone)><gCal:timezone value="#arguments.argTimezone#"></gCal:timezone></cfif>
<gCal:hidden value="false"></gCal:hidden>
<gCal:accesslevel value="owner" />
<gCal:color value="#arguments.argColor#"></gCal:color>
<gd:where rel='' label='' valueString='Oakland'></gd:where>
</entry>
</cfoutput>
</cfxml>
<cfhttp url="#variables.baseURL#/default/owncalendars/full" method="post" redirect="false" multiparttype="related" charset="utf-8">
<cfhttpparam type="header" name="Authorization" value="GoogleLogin auth=#getAuth(variables.serviceName)#">
<cfhttpparam type="header" name="Content-Type" value="application/atom+xml">
<cfhttpparam type="header" name="GData-Version" value="2">
<cfhttpparam type="body" value="#trim(locals.xml)#">
</cfhttp>
任何帮助都将不胜感激。
答案 0 :(得分:0)
CFXML创建一个ColdFusion XML对象。这是一个内部CFML构造,对接收API没有任何意义。我希望您需要将其转换为文本。
尝试使用ToString()包装locals.xml。像这样:
<cfhttp url="#variables.baseURL#/default/owncalendars/full" method="post"
redirect="false" multiparttype="related" charset="utf-8">
<cfhttpparam type="header" name="Authorization" value="GoogleLogin
auth=#getAuth(variables.serviceName)#">
<cfhttpparam type="header" name="Content-Type"
value="application/atom+xml">
<cfhttpparam type="header" name="GData-Version" value="2">
<cfhttpparam type="body" value="#trim(toString(locals.xml))#">
</cfhttp>
答案 1 :(得分:0)
我首先将您发送的XML输出到文本框并在屏幕上显示,以验证它的格式是否正确:
<textarea rows="30" cols="120">
<cfoutput>#trim(toString(locals.xml))#</cfoutput>
</textarea>
您可能考虑的另一种方法是将XML构建为字符串,而不是以后转换为字符串的本机ColdFusion XML对象:(注意我使用的是CFSaveContent而不是CFXML)
<cfsavecontent variable="locals.xml">
<cfoutput>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005" xmlns:gCal="http://schemas.google.com/gCal/2005">
<title type="text">#arguments.argTitle#</title>
<summary type="text">#arguments.argSummary#</summary>
<cfif len(arguments.argTimezone)><gCal:timezone value="#arguments.argTimezone#"></gCal:timezone></cfif>
<gCal:hidden value="false"></gCal:hidden>
<gCal:accesslevel value="owner" />
<gCal:color value="#arguments.argColor#"></gCal:color>
<gd:where rel='' label='' valueString='Oakland'></gd:where>
</entry>
</cfoutput>
</cfsavecontent>