Delphi-PRAXiS
Seite 1 von 7  1 23     Letzte »    

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   XLM Payload als Post (https://www.delphipraxis.net/189945-xlm-payload-als-post.html)

strom 10. Aug 2016 12:20

XLM Payload als Post
 
Hallo,

bekomme immer die Fehlermeldung : "HTTP/1.0 301 Moved Permanently" ?

Delphi-Quellcode:
function ExecuteAPI: string;
var
  lHTTP: TIdHTTP;
  lParamList: TStringList;
begin
  lParamList := TStringList.Create;
  lParamList.Add('<?xml version="1.0" encoding="UTF-8">');
  lParamList.Add('<testOperation version="1.0> ');
  lParamList.Add('<uniqueId>blablablabla</uniqueId>');
  lParamList.Add('<basicData>');
  lParamList.Add('<externalNumber>OF120131</externalNumber>');
  lParamList.Add('<keyword>F2/keyword>');
  lParamList.Add('<announcement>Test</announcement>');
  lParamList.Add('<location>Teststrasse 1</location>');
  lParamList.Add('<geo_location>');
  lParamList.Add('</basicData>');
  lParamList.Add('</testOperation>');
  lHTTP := TIdHTTP.Create(nil);
  try
    Result := lHTTP.Post('http://login.test.info/api?authkey=blablablabla=&call=operationData', lParamList);
  finally
    lHTTP.Free;
    lParamList.Free;
  end;
end;
Aufruf

Delphi-Quellcode:
begin
 ExecuteAPI;
end;

mkinzler 10. Aug 2016 12:57

AW: XLM Payload als Post
 
Die Url stimmt?

Die Xml-Struktur ist so auch nicht ganz korrekt

strom 10. Aug 2016 13:24

AW: XLM Payload als Post
 
Hey,
was ist an der Struktur falsch?

URL ,müsste so richtig sein!

-=ZGD=- 10. Aug 2016 13:27

AW: XLM Payload als Post
 
Zitat:

Zitat von mkinzler (Beitrag 1344593)
Die Url stimmt?

Noch!
Diese wurde wohl umgezogen.
Die Information sollte im Response stehen: Location gibt die neue URL an.

himitsu 10. Aug 2016 13:31

AW: XLM Payload als Post
 
Zitat:

Code:
<testOperation version="1.0>

Da fehlt mindestens ein "

Und IdHTTP überträgt das dann auch wirklich als UTF-8?
In der XML steht, dass sie UTF-8 ist,
aber was InHTTP macht, ist eine andere Angelegenheit.

Tipp: ParamList speichern und die Datei an http://www.xmlvalidation.com/?L=2 übergeben.

mjustin 10. Aug 2016 13:49

AW: XLM Payload als Post
 
Es darf keine TStringList verwendet werden. Indy benutzt dann für den Request das Format application/x-www-form-urlencoded.

Stattdessen muss ein Stream verwendet werden, zum Beispiel ein TStringStream.

Ein Beispiel für ein HTTPS POST mit einem JSON Body habe ich hier:

https://mikejustin.wordpress.com/201...-6-https-post/

Delphi-Quellcode:
program JSONPostExample;
 
{$APPTYPE CONSOLE}
 
uses
  IdHTTP, IdGlobal, SysUtils, Classes;
 
var
  HTTP: TIdHTTP;
  RequestBody: TStream;
  ResponseBody: string;
begin
  HTTP := TIdHTTP.Create;
  try
    try
      RequestBody := TStringStream.Create('{"&#26085;&#26412;&#35486;":42}',
        TEncoding.UTF8);
      try
        HTTP.Request.Accept := 'application/json';
        HTTP.Request.ContentType := 'application/json';
        ResponseBody := HTTP.Post('https://httpbin.org/post',
          RequestBody);
        WriteLn(ResponseBody);
        WriteLn(HTTP.ResponseText);
      finally
        RequestBody.Free;
      end;
    except
      on E: EIdHTTPProtocolException do
      begin
        WriteLn(E.Message);
        WriteLn(E.ErrorMessage);
      end;
      on E: Exception do
      begin
        WriteLn(E.Message);
      end;
    end;
  finally
    HTTP.Free;
  end;
  ReadLn;
  ReportMemoryLeaksOnShutdown := True;
end.

strom 10. Aug 2016 16:59

AW: XLM Payload als Post
 
Hallo, bekomme es einfach nicht hin! Fehlercode E/A 105 ??

Delphi-Quellcode:
procedure TForm1.Button2Click(Sender: TObject);
var
  HTTP: TIdHTTP;
  RequestBody: TStream;
  ResponseBody: string;
begin
  HTTP := TIdHTTP.Create;
  try
    try
      RequestBody := TStringStream.Create('{123456789}',
        TEncoding.UTF8);
      try
        HTTP.Request.Accept := 'input.xml HTTP/1.0';
        HTTP.Request.ContentType := 'application/x-www-form-urlencoded';
        ResponseBody := HTTP.Post('http://login.fireboard.net/api?authkey={123456789}&call=operation_data',
          RequestBody);
        WriteLn(ResponseBody);
        WriteLn(HTTP.ResponseText);
      finally
        RequestBody.Free;
      end;
    except
      on E: EIdHTTPProtocolException do
      begin
        WriteLn(E.Message);
        WriteLn(E.ErrorMessage);
      end;
      on E: Exception do
      begin
        WriteLn(E.Message);
      end;
    end;
  finally
    HTTP.Free;
  end;
  ReadLn;
  ReportMemoryLeaksOnShutdown := True;
end;

mjustin 10. Aug 2016 18:48

AW: XLM Payload als Post
 
Zitat:

Zitat von strom (Beitrag 1344616)
Hallo, bekomme es einfach nicht hin! Fehlercode E/A 105 ??

Delphi-Quellcode:
...

... in welcher Zeile?

Fritzew 10. Aug 2016 18:53

AW: XLM Payload als Post
 
Hast Du eine Console offen in Deinem Programm?
Wenn nicht kommentiere mal die readln und writeln Zeilen aus.........

-=ZGD=- 10. Aug 2016 20:02

AW: XLM Payload als Post
 
Liste der Anhänge anzeigen (Anzahl: 1)
Das liegt aber daran, dass du den HTTP/301 bekommst. Dieser besagt nach wie vor: Moved permanently...

Anhang 45688

Wie du siehst erfolgt der Request nun über HTTPS.

Warum ist das Bild so klein :(

Zum E/A 105

Code:
WriteLn()
schön und gut. Damit du einen wirklichen Nutzen davon hast: Projektoptionen -> Delphi-Compiler (Linken) -> Konsolenanwendung erzeugen auf
Code:
true
Ich mag die Konsole zum Entwickeln sehr gern, denn das kleine Fenster stört nicht und hilft ausgesprochen gut. Vergiss aber nicht, beim Ausliefern den oben genannten Schalter wieder zu deaktivieren.

Ansonsten möchte WriteLn() natürlich irgendwo hinschreiben. Aber wenn du einen Stift hast und kein Papier, hast du auch nen E/A 105 ;-)


Alle Zeitangaben in WEZ +1. Es ist jetzt 08:36 Uhr.
Seite 1 von 7  1 23     Letzte »    

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz