[英]How to change Content-Type:application/json into html in response header
[英]How to change the Content-Type response in the REST DataSnap
我有一個由WebBroker REST
制作的項目,作為服務運行,我需要將Cotent-Type
響應更改為application/json
,默認情況下, WebBroker REST
將我帶來了結果
Content-Type'text / html; 字符集= ISO-8859-1'
我通過訪問方法更改響應
GetInvocationMetadata(True).ResponseContentType ='application / json'
Data.DBXPlatform
類的數據,但它仍然無法解析它,它會在當前Content-Type
下面添加另一個Content-Type
。
這只發生在WebBroker REST
,如果我通過DataSnap Server創建項目,我通常會得到它。 但我需要WebBroker REST
來訪問客戶端發送給我的信息。
如何解決問題的示例。
DataSnap REST Application
創建項目 在ServerMethods類中,執行相同的模型。
uses System.StrUtils, Data.DBXPlatform;
function TServerMethods1.EchoString(Value: string): string;
begin
Result := Value;
GetInvocationMetadata.ResponseContentType := 'application/json';
end;
示例響應標頭。
連接:關閉
內容類型:text / html; 字符集= ISO-8859-1
內容長度:25
日期:2013年9月10日星期二16:41:37 GMT
Pragma:dssession = 542354.126073.592372,dssessionexpires = 1200000
Content-Type:application / json
在New DataSnap WebBroker應用程序向導中,您可以選擇創建單獨的服務器模塊。 在生成的單元WebModuleUnit1.pas中有一個變量WebModuleClass,它是TWebModule的后代。 此WebModuleClass對象具有類型為TWebResponse的公共屬性Response,它使您能夠設置ContentType。
http://docwiki.embarcadero.com/Libraries/Berlin/en/Web.HTTPApp.TWebResponse.ContentType
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.