Einzelnen Beitrag anzeigen

mjustin

Registriert seit: 14. Apr 2008
3.017 Beiträge
 
Delphi 2009 Professional
 
#1

AW: FritzBox auslesen - Problem SOAP-Abfrage

  Alt 25. Sep 2025, 14:13
Delphi-Quellcode:
   Content : TStringList;

...
    result := HTTP.Post(url, Content);
Da liegt der Fehler: es muss für XML oder JSON hier keine Stringlist sondern ein Stream übergeben werden.

Siehe hier: https://blog.habarisoft.com/2015/03/...-6-https-post/

"you must not use a TStringList for the POST body. That version of TIdHTTP.Post() formats the data according to the application/x-www-form-urlencoded media type, which is not appropriate for JSON and will corrupt it."


Delphi-Quellcode:
RequestBody: TStream;
ResponseBody: string;
...

RequestBody:= TStringStream.Create(Content.Text, TEncoding.UTF8);

ResponseBody := HTTP.Post(url, RequestBody);
Michael Justin

Geändert von mjustin (25. Sep 2025 um 14:18 Uhr)
  Mit Zitat antworten Zitat