rest - 将数据作为应用程序/JSON 发送会引发错误

标签 rest coldfusion

我想通过正文发送数据 application/json .这是我的要求:
Image of request data

但有了这个,我只能得到:

The @FormParam is utilized when the content type of the request entity is not application/x-www-form-urlencoded



Image of error

我的代码:
<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/

相关文章:

coldfusion - 定义自定义数据类型?

scala - 来自 Spark Streaming 的 Rest API 服务调用

android - 使用 Fitnesse 测试的 Android 中出现错误 java.lang.RuntimeException : Stub!

java - Angular $http.get 总是在使用本地 Restful 服务时出现错误

coldfusion - 在 ColdFusion 8 中创建下载页面

javascript - Coldfusion - 使用列表

android - Django REST框架: Directly display on results list in GenericView

ajax - 如何将字符串参数传递给自定义存储库方法?

regex - 如何使用 RegEx 禁止 ColdFusion 中的非字母数字字符

java - 冷聚变 : Runtime show logs on CF page just like Console or Putty