Einzelnen Beitrag anzeigen

ScharfeMietze

Registriert seit: 5. Mär 2014
165 Beiträge
 
Delphi 10.2 Tokyo Architect
 
#41

AW: rest server wie muss das post Command aussehen oder welchen Server könnte ich ver

  Alt 22. Okt 2019, 14:46
Versuch mal folgendes:

Die WebhookAction nimmst du wieder raus.
Die Funktion TServerMethods1.Webhook ebenfalls raus.

und dann sowas in der Art:

function TServerMethods1.updateWebhook(Value: TJSONObject): TJSONObject;
begin
Result := Value;
fConnect.Memo1.Lines.Add('Webhook update' + Value.ToJSON);
end;

Und das ganze dann mit ..../Webhook/ und einem JSON-Text im Body als "Post" posten.

Im Server sieht es nun so aus

Delphi-Quellcode:
function TServerMethods1.updateWebhook(Value: TJSONObject): TJSONObject;
begin
  Result := Value;
  fConnect.Memo1.Lines.Add('Webhook update' + Value.ToJSON);
end;

function TServerMethods1.Webhook(Value: TJSONObject): TJSONObject;
begin
  Result := Value;
   fConnect.Memo1.Lines.Add('Webhook ' + Value.ToJSON);
end;

Gesendet habe ich es so


Delphi-Quellcode:
procedure TfClient.btn1Click(Sender: TObject);
const
  Url = 'https://alpt.kxmwm3epa9wmpje7.myfritz.net/datasnap/rest/TServerMethods1/Webhook/';
// Url = 'https://alpt.kxmwm3epa9wmpje7.myfritz.net/datasnap/rest/TServerMethods1/Webhook/data/';
//POST /datasnap/rest/TServerMethods1/%22updateEchoAttribute%22/Attr1
var
  LsList: TStringList;
  LsStream: TStringStream;
begin
nthtpclnt1.ContentType:= 'application/x-www-form-urlencoded';
LsList := TStringlist.Create;
  try
  LsStream := TStringStream.Create;
    try
      LsList.Add('{"webhook":"John"}');
      nthtprqst1.Post(Url,LsList,LsStream, TEncoding.Default) ;
      mmo1.Lines.Add(UTF8Decode(LsStream.DataString));
    finally
      LsStream.Free;
    end; // try
  finally
    LsList.Free;
  end; // try
end;


Retour bekomme ich

{"error":"Ung\u00FCltige Typumwandlung"}
  Mit Zitat antworten Zitat