-
-
Notifications
You must be signed in to change notification settings - Fork 44
(server) modificar o ContentType (do HTML Response) para retornar ao Client, em ServerEvents ou ServerContexts
Joseh-Henrique edited this page Jun 10, 2022
·
2 revisions
Retornar para o Client outro ContentType para um ServerEvent, diferente de 'application/json'.
Exemplo: ocorreu um erro e é necessário retornar uma string de retorno, com a mensagem de erro ('text/html'), não necessariamente um json.
obs: ServerContexts já têm um parâmetro ContentType com a mesma função, neste caso esta alteração servirá mais se trabalhar com ServerContexts e ServerEvents na mesma aplicação, e quiser padronizar seu código.
Em um evento OnReplyEvent de um Evento de um DWServerEvents (ou OnReplyRequest de um Evento de um DWServerContext):
// retornar um novo DWParam com nome 'ContentType'
var cType: TJSONParam;
cType := TJSONParam.Create(esUtf8);
cType.ParamName := 'ContentType';
cType.ObjectDirection := odOUT;
cType.ObjectValue := ovString;
cType.Value := 'text/html';
Params.Add(cType);