Einzelnen Beitrag anzeigen

horstmeyer

Registriert seit: 9. Aug 2021
45 Beiträge
 
#1

IdHTTPost funktioniert nicht

  Alt 9. Aug 2021, 10:38
Hallo Leute,

ich bin neu hier und hoffe mir kann jemand weiterhelfen. Für TSE(https://de.wikipedia.org/wiki/Techni...itseinrichtung) muss ich eine idHTTP-Funktion schreiben. idhttp.get funktioniert auch, aber bei http.post bekomme ich immer die Fehlermeldung 400. In einer Batch-Datei mit curl funktioniert der Aufruf aber. Hier der Aufruf mit curl:
Code:
curl -X POST "http://localhost:20001/transaction" -H "Content-Type: application/json" -H "Authorization: Bearer %accesstoken%" -d "{\"clientId\": \"TestEAS002\",\"processType\": \"Bestellung-V1\",\"processData\": \"1^%ware%^999 Euro\",\"externalTransactionId\": \"%extaid%\"}"
Und hier der Aufruf mit Delphi, der leider nicht funktioniert, obwohl ich mir die Syntax hier abgeschaut habe:
Code:
procedure TForm1.FCCStart;
var
  ware,
  data,
  Answer : String;
  DataToSend : TStringList;
  lHTTP: TIdHTTP;
begin
  lblStatus.Caption:='Request gestartet...';
  lHTTP := TIdHTTP.Create;
  try
    try
      lHTTP.HandleRedirects := True;
      lHTTP.ReadTimeout := 5000;
      ware := 'Testware';
      data := '{"clientId": "TestEAS002","processType": "Bestellung-V1","processData": "1^'+ware+'^999 Euro","externalTransactionId": "'+extaid+'"}';
      DataToSend := TStringList.create;
      DataToSend.Add(data);
      try
        lHTTP.Request.Accept := 'application/json';
        lHTTP.Request.ContentType := 'application/json';
        lHTTP.Request.CustomHeaders.FoldLines := False;
        lHTTP.Request.CustomHeaders.Add('Authorization:Bearer '+accesstoken);
        Answer := lHTTP.Post('http://localhost:20001/transaction', DataToSend);
      finally
        DataToSend.Destroy;
      end;
      Memo1.Lines.Clear;
      Memo1.Lines[0]:=Answer;
    except
      on E: Exception do
        lblStatus.Caption:=E.ToString;
    end;
  finally
    lHTTP.Destroy;
  end;
end;
Viele Grüße
Horst
  Mit Zitat antworten Zitat