2014-02-14 21 views
0

以下是將enctype屬性添加到表單標記並觀察傳遞的參數丟失的一個簡單示例。Coldfusion 10 Rest Services和enctype的剩餘資源值應該是多少?

## test.rest.cfm 
<!doctype html> 
<html> 
<head> 
<title>Test Form</title> 
</head> 
<body> 
<div> 
<p>Will Post From Here</p> 
<form method="post" action="http://devserver/rest/ost/testform/" name="frmName"> 
<table> 
<tr> 
<td>fname</td> 
<td><input type="text" name="fname" id="fname" value="Fredley"></td> 
</tr> 
<tr> 
<td>lname</td> 
<td><input type="text" name="lname" value="Solongo"></td> 
</tr> 
<tr> 
<td>&nbsp;</td> 
<td><input type="submit" value="Post"></td> 
</tr> 
</table> 
</form> 
</div> 
</body> 
</html> 

## testFormHandler.cfc 
<cfcomponent restpath="testform" rest="true" produces="application/JSON"> 

<cffunction description="POST method to test form" 
name   = "postMethod" 
access  = "remote" 
output  = "false" 
returntype = "string" 
returnformat = "json" 
httpmethod = "post" > 

<cfargument required="1" type="any" restArgSource="Form" name="fname"> 
<cfargument required="1" type="any" restArgSource="Form" name="lname"> 

<cfset var arrayReturn = {}> 
<cfset arrayReturn["fname"] = arguments.fname> 
<cfset arrayReturn["lname"] = arguments.lname> 

<cfreturn "{""PayLoad"":" & SerializeJSON(arrayReturn) & ",""Type"":""Success"",""Message"":""SUCCESS"",""Code"":""SUCCESS""}"> 

</cffunction> 

</cfcomponent> 

## change form tag of test.rest.cfm to gets param fname failure 
<form method="post" action="http://dev1.ostit.com/rest/ost/testform/" name="frmName" enctype="multipart/form-data"> 

## results with no enctype 
{"PayLoad":{"fname":"Fredley","lname":"Solongo"},"Type":"Success","Message":"SUCCESS","Code":"SUCCESS"} 

## results with enctype added 
{"Message":"The FNAME parameter to the postMethod function is required but was not passed in."} 

當包含enctype時restArgSource應該不同麼?顯然,HTTP頭改變,但使用頭與restargname沒有工作,要麼...

回答

0

getting started guide這樣說:

「此外,還必須設置Content-Type頭的應用程序/ X-以表單字段的形式發送數據時,www-form-urlencoded。「

所以,你可能會運氣不好,我很害怕。您可能能夠獲得底層http請求的句柄並像這樣訪問請求主體,但這將是相當多的工作。使用多部分表單的原因是什麼?我猜想文件上傳,但我有興趣知道是否有另一個用例。

它看起來像使用常規CFFile處理file upload itself will work in REST。如果你可以處理在URL上放置其他參數,你可能會得到一些可行的方法。