使用ColdFusion 10的REST服务,为什么使用带有原始json主体的PUT方法的发布请求导致空字符串

问题描述

首先,此代码段来自https://www.youtube.com/watch?v=4GkXanOqH88,可在ColdFusion 11上使用,但在CF10上使用它时遇到了问题。

发送以下请求:

PUT /rest/api/expenseAPI/user/1 HTTP/1.1
Host: localhost:5080
Content-Type: application/json
authorization: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1OTg0ODI3NzYsInRzIjoiQXVndXN0LCAyNiAyMDIwIDE1OjI5OjM2IiwidXNlcmlkIjoxfQ.DRhNXWghiGmQThe1ae8KATAfl2pO5e3-g3ERUf3MzMU

{
    "firstname": "John","lastname": "Smith","email": "test@testing.com"
}

...到以下函数应将JSON正文传递给structform参数,但是structform参数将导致一个空字符串!我发现,如果我将httpmethod更改为POST并发送了POST请求,则该请求可以正常工作。这是CF10错误还是什么?

<cfcomponent rest="true" restpath="expenseAPI">
...
    <cffunction name="putuser" restpath="user/{id}" access="remote" returntype="struct" httpmethod="PUT" produces="application/json">
    <cfargument name="id" type="any" required="yes" restargsource="path"/>
    <cfargument name="structform" type="any" required="yes">
    
    <cfset var response = {}>

    <cfset verify = authenticate()>
    <cfif not verify.success>
        <cfset response["success"] = false>
        <cfset response["message"] = verify.message>
        <cfset response["errcode"] = 'no-token'>
    <cfelse>
        <cfset response = objUser.updateUser(arguments.id,arguments.structform)>
    </cfif>

    <cfreturn response>

</cffunction>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)