2017-07-19 1 views
2

データベースの入力値をチェックしてメッセージ(成功/失敗)を返すColdFusionでWebサービスを作成しました。 CFCを実行するには 、私が直接このように、URL内の引数を提供しています: http://localhost/AimsWeb/Authenticate2.cfc?method=AuthenticateUser&returnformat=json&CustomerID=1&username=xxx&password=xxxx しかし、私はこのページを実行すると、それは以下のようなエラーで終了します。 enter image description herecfcを実行中にエラーが発生しました:関数から返された値がjson型ではありません

これは私のCFCです。

<cfcomponent rest="true" restpath="/AimsWeb"> <!--- REST Service---> 

<cffunction name="AuthenticateUser" access="remote" httpmethod="POST" returnFormat="JSON" returntype="json"> 

<!---- Defining Arguments---> 
    <cfargument name="Username" type="string" required="Yes"> 
    <cfargument name="Password" type="string" required="Yes"> 
    <cfargument name="CustomerID" type="string" required="Yes"> 

<!---- Setting the Form Values (which we will get from AW+) and setting it to arguments passed---> 
    <cfset Form.CustomerID = arguments.CustomerID> 
    <cfset Form.Username = arguments.Username> 
    <cfset Form.Password = Hash(arguments.Password)> 

<cfif StructKeyExists (form, 'CustomerID') and StructKeyExists(form, 'UserName') and StructKeyExists (form, 'password')> 
    <cfquery name="AllUsers" datasource="#Application.GomDatasource#"> 
    SELECT u.UserTypeID, u.UserID, u.CustomerID, u.UserName, u.Password 
    FROM tblUsers u 
    WHERE u.CustomerID = <cfqueryparam cfsqltype="cf_sql_integer" value="#Form.CustomerID#"> 
    </cfquery> 



<!--- This is to check whether provided parameters are valid by checking the same in the database---> 
<cfset local.StatusStruct = StructNew()> 

<cfif form.customerid EQ "" OR form.username EQ "" OR form.password EQ ""> 
    <cfset local.StatusStruct['errorCode'] = 400> 
    <cfset local.StatusStruct['errorMessage'] = "Insufficient Input."> 

<cfelseif AllUsers.RecordCount AND form.CustomerId EQ AllUsers.CustomerID AND form.username EQ AllUsers.UserName AND form.password EQ AllUsers.Password> 
    <cfset local.StatusStruct['errorCode'] = 200> 
    <cfset local.StatusStruct['errorMessage'] = "Success"> 

<cfelseif AllUsers.CustomerID NEQ form.CustomerID> 
    <cfset local.StatusStruct['errorCode'] = 400> 
    <cfset local.StatusStruct['errorMessage'] = "Customer Id doesn't exist"> 

<cfelseif AllUsers.UserName NEQ form.UserName> 
    <cfset local.StatusStruct['errorCode'] = 400> 
    <cfset local.StatusStruct['errorMessage'] = "User not found"> 

<cfelseif AllUsers.Password NEQ form.password> 
    <cfset local.StatusStruct['errorCode'] = 400> 
    <cfset local.StatusStruct['errorMessage'] = "Invalid Password"> 
</cfif> 

    <!--- Returning the status in JSON form---> 

</cfif> 
<cfreturn local.StatusStruct> 
    </cffunction> 

</cfcomponent> 

誰でも教えてください。

+0

local.StatusStructをjsonに変換する部分はどこですか? –

+0

URLのユーザーとパスワード...なぜですか? – Hackerman

+0

@DanBracuk:returnFormat = "json"と指定すると、戻り値が自動的にJSON文字列に変換されます。(?) – Vasu

答えて

2

それは働いた。 returntype=jsonは無効です。私はその行を削除し、それは働いた。

<cffunction name="AuthenticateUser" access="remote" httpmethod="GET" returnFormat="JSON"> 

ありがとうございました。

関連する問題