我想通过正文发送数据 application/json
.这是我的要求:
但有了这个,我只能得到:
The @FormParam is utilized when the content type of the request entity is not application/x-www-form-urlencoded
我的代码:
<cffunction name="createInstance" access="remote" returntype="any" produces="application/json" httpmethod="POST" restpath="/instances">
<cfargument name="customerId" required="true" restArgSource="form" type="string" default=""/>
<cfargument name="name" required="true" restArgSource="form" type="string" default=""/>
<cfargument name="datasource" required="false" restArgSource="form" type="string" default=""/>
<cfargument name="startDate" required="true" restArgSource="form" type="string" default=""/>
<cfargument name="expirationDate" required="false" restArgSource="form" type="string" default=""/>
<cfargument name="amount" required="true" restArgSource="form" type="numeric" default=-1/>
<cfreturn name>
</cffunction>
最佳答案
通常 JSON 处理程序应该用作 GET 方法。您可以尝试使用 httpmethod 作为 GET 和 restArgSource 作为路径。
<cffunction name="createInstance"
access="remote"
returntype="any"
produces="application/json"
httpmethod="GET"
restpath="/instances">
<cfargument name="customerId" required="true"
restArgSource="Path" type="numeric" />
如果您仍然需要将请求作为 POST,您能否分享标题选项卡?
关于rest - 将数据作为应用程序/JSON 发送会引发错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57799915/