我正在ColdFusion中編寫一個簡單的RESTful Web服務(cfc),並希望將JSON字符串傳遞給相同的服務。事情是這樣的:如何將JSON字符串傳遞到我的ColdFusion Web服務並返回成功/失敗消息?
我已經寫了類似如下:
{
"CustomerID": 100,
"UserName": "test",
"Password": "xxxxx",
}
另外,我想驗證後返回成功/失敗消息。 任何想法我應該如何實現這一目標?
<cfcomponent rest="true" restpath="/folder">
<cfscript>
record=deserializeJSON(
'{
"CustomerID": 100,
"UserName": "aimsweb",
"Password": "xxxxx",
}'
);
</cfscript>
<cffunction name="UserDetails" returnType="JSON" access="remote" HttpMethod="GET">
<cfargument name="Username" type="string" required="Yes">
<cfargument name="Password" type="string" required="Yes">
<cfargument name="CustomerID" type="string" required="Yes">
<cfset Form.CustomerID = arguments.CustomerID>
<cfset Form.Username = arguments.Username>
<cfset Form.Password = Hash(arguments.Password)>
<cfquery name="AW1Users" datasource="#request.app.dsn#">
SELECT * FROM tableName where UserName='xxxx'
</cfquery>
<cfif AW1Users.RecordCount>
<cfthrow errorcode="200"
detail="Success"
message="Success"
type="Application">
<cfelseif AW1Users.CustomerID NEQ form.CustomerID>
<cfthrow errorcode="400"
detail="Customer Id doesn't exist"
message="Customer Id doesn't exist"
type="Application">
</cfif>
<cfreturn AW1Users>
</cffunction>
</cfcomponent>
謝謝!!我很感激。 – Vasu
但任何想法應該如何將JSON傳遞給此Web服務? – Vasu
檢查更新的答案..希望它會有所幫助 –