我有一个由 WebBroker REST
制作的项目,作为服务运行,我需要将 Cotent-Type
响应更改为 application/json
,默认情况下 WebBroker REST
带来了我的结果
Content-Type'text / html;字符集= ISO-8859-1'
我通过访问方法更改响应
GetInvocationMetadata(True).ResponseContentType ='application / json'
的 Data.DBXPlatform
类,但它仍然没有解决它,它在当前的一个下方添加了另一个 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
1 回答
在New DataSnap WebBroker应用程序向导中,您可以选择创建单独的服务器模块 . 在生成的单元WebModuleUnit1.pas中有一个变量WebModuleClass,它是TWebModule的后代 . 此WebModuleClass对象具有类型为TWebResponse的公共属性Response,它使您能够设置ContentType .
http://docwiki.embarcadero.com/Libraries/Berlin/en/Web.HTTPApp.TWebResponse.ContentType