3

I have a project made from WebBroker REST, running as a service, I need to change theCotent-Type response to application/json and by default WebBroker REST brings me as a result the

Content-Type 'text/html; charset=ISO-8859-1'

I change the response by accessing the method

GetInvocationMetadata(True).ResponseContentType = 'application/json'

of the Data.DBXPlatform class, but it still does not resolve it it adds anotherContent-Type just below the current one.

This only happens only in WebBroker REST, if I create a project by DataSnap Server I usually get it. But I need WebBroker REST to access the information the client sends me.

Example of how to make the problem occur.

  • Create a Project from the DataSnap REST Application

In the ServerMethods class, do the same model.

uses System.StrUtils, Data.DBXPlatform;

function TServerMethods1.EchoString(Value: string): string;
begin
  Result := Value;
  GetInvocationMetadata.ResponseContentType := 'application/json';
end;

Example response Header.

Connection: close
Content-Type: text/html; charset=ISO-8859-1
Content-Length: 25
Date: Tue, 10 Sep 2013 16:41:37 GMT
Pragma: dssession=542354.126073.592372,dssessionexpires=1200000
Content-Type: application/json

Jefferson Rudolf
  • 161
  • 2
  • 11

1 Answers1

4

In New DataSnap WebBroker Application Wizard you have the option to create a separate Server Module. In the generated unit WebModuleUnit1.pas there is a variable WebModuleClass, which is a descendant of TWebModule. This WebModuleClass object has a public property Response of type TWebResponse, which gives you ability to set ContentType.

http://docwiki.embarcadero.com/Libraries/Berlin/en/Web.HTTPApp.TWebResponse.ContentType

Erwin
  • 1,896
  • 1
  • 11
  • 17
  • 1
    I use Delphi XE7, in WebModuleUnit1.pas create function. procedure TWebModule1.WebModuleAfterDispatch(Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean); begin Response.ContentType := 'application/json'; end; and response header is. Connection: close Content-Type: application/json; charset=ISO-8859-1 Content-Length: 25 Date: Tue, 10 Sep 2013 16:41:37 GMT Pragma: dssession=542354.126073.592372,dssessionexpires=1200000 but i need in content-type only application/json, has as? – Jefferson Rudolf Jan 31 '17 at 13:42
  • Do you have any idea? – Jefferson Rudolf Jan 31 '17 at 16:53