ColdFusion 10 の新しいビルトイン REST API を使用しており、ステータス コード 201 (作成済み) を返したいと考えています。ここで説明されている RestSetResponse() アプローチを最初に試しました: http://www.adobe.com/devnet/coldfusion/articles/restful-web-services.html。関数の returntype を「void」に設定する必要があることを除いて、これはうまく機能します。「void」の問題は、例外をスローするたびに、適切な JSON エラー メッセージが返されなくなることです。
この例外をスローする:
<cfthrow errorcode="400" message="Validation error." />
returntype が「struct」の場合、きれいにフォーマットされた JSON を返します。
HTTP/1.1 400 Bad Request
Content-Type: application/json
{"Message":"Validation error."}
しかし、returntype が "void" (RestSetResponse() を使用するために必要) の場合、応答は見苦しい HTML 応答になります。
このため、returntype "struct" の使用に戻さなければならず、RestSetResponse() をあきらめ、これを試しました。
<cfheader statusCode="201" statusText="Created" />
しかし、うまくいきません。ColdFusion は statusCode を上書きし、成功すると常に 200 (OK) を返すようです。関数の returntype を「void」に設定せずにステータスコードを 201 に変更する方法を知っている人はいますか?