I have a REST Service. By default, the JSON data being returned has all the NULLs eliminated. This is causing me difficulties, so I have a request header setting that changes the behavior. The request header I need to add is: Accept-Formatting: json-nulls=include
I have been able to get to work from POSTMAN, using the following format.
I have not been able to get this to work from my application.
My application has a TRestClient, TRestResponse and TRestRequest.
I have tried adding this as a parameter on both TRestClient and TRestRequest. While the REST service returns the data, the NULL fields are not being displayed, which tells me that my format (or something else relating to the request header) is not correct. Where and HOW should this be added?
Any thoughts appreciated.
答案 0 :(得分:0)
答案 1 :(得分:0)
如果您想以编程方式发送 firebase 通知,您可以尝试我使用的方式,它对我有用。
{Send a notification to Firebase Messaging.
@param Titulo Notification title
@param Mensagem Notification message
@param Page The page the user will be redirected after the notification is clicked Ex: `/home`}
function EnviarNotificacao(Titulo, Mensagem, Page: string): string;
var
RESTClient1: TRESTClient;
RESTRequest1: TRESTRequest;
RESTResponse1: TRESTResponse;
JsonBody, JsonNotification, JsonData, JsonResponse: TJSONObject;
begin
RESTClient1 := TRESTClient.Create(nil);
RESTRequest1 := TRESTRequest.Create(nil);
RESTResponse1 := TRESTResponse.Create(nil);
RESTRequest1.Client := RESTClient1;
RESTRequest1.Response := RESTResponse1;
RESTRequest1.Method := TRESTRequestMethod.rmPOST;
RESTRequest1.Params.AddItem('Authorization', 'key=AAAd...', pkHTTPHEADER, [poDoNotEncode]);
RESTClient1.BaseURL := 'https://fcm.googleapis.com/fcm/send';
JsonBody := TJSONObject.Create;
JsonNotification := TJSONObject.Create;
JsonData := TJSONObject.Create;
JsonNotification.AddPair('title', Titulo);
JsonNotification.AddPair('body', Mensagem);
JsonData.AddPair('click_action', 'FLUTTER_NOTIFICATION_CLICK');
JsonData.AddPair('page', Page);
JsonBody.AddPair('notification', JsonNotification);
JsonBody.AddPair('data', JsonData);
JsonBody.AddPair('to', '/topics/your_topic');
RESTRequest1.AddBody(JsonBody);
RESTRequest1.Execute;
JsonResponse := RESTResponse1.JSONValue as TJSONObject;
Result := JsonResponse.ToString;
end;
你也应该释放TJSONObject
,我没有这样做,因为我很着急。