![]() |
XLM Payload als Post
Hallo,
bekomme immer die Fehlermeldung : "HTTP/1.0 301 Moved Permanently" ?
Delphi-Quellcode:
Aufruf
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;
Delphi-Quellcode:
begin
ExecuteAPI; end; |
AW: XLM Payload als Post
Die Url stimmt?
Die Xml-Struktur ist so auch nicht ganz korrekt |
AW: XLM Payload als Post
Hey,
was ist an der Struktur falsch? URL ,müsste so richtig sein! |
AW: XLM Payload als Post
Zitat:
Diese wurde wohl umgezogen. Die Information sollte im Response stehen: Location gibt die neue URL an. |
AW: XLM Payload als Post
Zitat:
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 ![]() |
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: ![]()
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('{"日本語":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. |
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; |
AW: XLM Payload als Post
Zitat:
|
AW: XLM Payload als Post
Hast Du eine Console offen in Deinem Programm?
Wenn nicht kommentiere mal die readln und writeln Zeilen aus......... |
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:
schön und gut. Damit du einen wirklichen Nutzen davon hast: Projektoptionen -> Delphi-Compiler (Linken) -> Konsolenanwendung erzeugen auf
WriteLn()
Code:
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.
true
Ansonsten möchte WriteLn() natürlich irgendwo hinschreiben. Aber wenn du einen Stift hast und kein Papier, hast du auch nen E/A 105 ;-) |
AW: XLM Payload als Post
Hier eine Anleitung zur Schnittstelle, habe es immer noch nicht! :shock:
Der API Aufruf für Einsatzdaten ist an einen Fireboard-Portal-Account gekoppelt. Ein Fireboard-Portal-Account hat für diese API einen Authentifizierungsschlüssel (authkey) der jedem Aufruf mit gegeben werden muss. Zusätzlich muss der Aufruf durch einen Aufrufschlüssel (call) identifiziert werden. Folgende API-URL ergibt sich demzufolge: http://login.fireboard.net/api?authkey={key}&call=operationData Dem Aufruf wird ein XML Payload als POST mitgegeben. Die Daten für einen Einsatz enthalten die wichtigsten einsatzrelevanten Angaben: Einsatzstichwort Alarmnachricht Einsatzbeginn Leitstellennummer Einsatzort (plus geografische Koordinate im Dezimalgradformat) Lagebeschreibung Zusätzlich muss jeder Einsatz eine eindeutige Einsatzidentifikationsnummer besitzen um nachträglich eingelieferte Daten diesem Einsatz zuordnen zu können. Die Einsatzidentifikationsnummer muss für jeden einzelnen Kunden eineindeutig sein (also nach authkey). Datenstruktur <?xml version="1.0" encoding="UTF-8"?> <fireboardOperation version="1.0"> <uniqueId>11A1411EAB213194334CED</uniqueId> <basicData> <externalNumber>OF120137</externalNumber> <keyword>F2</keyword> <announcement>Wohnungsbrand</announcement> <location>Testphasen, Teststrasse 1</location> <geo_location> <latitude></latitude> <longitude></longitude> </geo_location> <timestampStarted> <long>1458028846582</long> </timestampStarted> <situation>Notruf über Anwohner</situation> </basicData> </fireboardOperation> <uniqueId> ist als Pflichtfeld zu verstehen, alle anderen Angaben innerhalb von <basicData> sind optional. Werden Felder frei gelassen, so befüllt das Fireboard-Portal die entsprechenden Felder mit plausiblen Daten zur späteren Anzeige im Portal. Wenn <timestampStarted> nicht befüllt wird, so übernimmt Fireboard zur Anzeige das Datum der Einlieferung der Daten. Eine spätere Korrektur auf <timestampStarted> ist jedoch möglich. |
AW: XLM Payload als Post
Was genau ist das Problem?
Das Handbuch ist falsch. Es ist wie gesagt HTTPS!!!!! noch immer...wie schon oft erwähnt und durch HTTP-Code 301 bestätigt.. |
AW: XLM Payload als Post
hey,
komme mit dem Fehler Code E/A 105 nicht klar! Habe es noch nicht verstanden :-( |
AW: XLM Payload als Post
Du hast in deinem Quelltext
Delphi-Quellcode:
stehen.
Writeln('iwas');
Entferne diese oder kommentiere sie aus. Das kommt daher, dass Delphi versucht diese Informationen auf die Konsole zu schreiben, du aber keine hast ;-) Und wenn nichts da ist, knallt es eben. |
AW: XLM Payload als Post
Hallo ZGD,
bekomme jetzt noch als Meldung: Wert für IOHandler ist ungültig?
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('https://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 Showmessage(E.Message); Showmessage(E.ErrorMessage); end; on E: Exception do begin ShowMEssage(E.Message); // Fehlermeldung : Wert für IOHandler ist ungültig !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! end; end; finally HTTP.Free; Memo1.Lines.Insert(0, FormatDateTime('hh:nn:ss',Now)); end; //ReadLn; //ReportMemoryLeaksOnShutdown := True; end; |
AW: XLM Payload als Post
Zitat:
Die aktuelle Indy Version erzeugt für HTTPS automatisch einen passenden IOHandler. Lösung: entweder den passenden TIdIOHandlerOpenSSL erzeugen und der IOHandler Property zuweisen, oder Indy aktualisieren. |
AW: XLM Payload als Post
Hallo,
würde mich für diese Lösung entscheiden: Lösung: entweder den passenden TIdIOHandlerOpenSSL erzeugen und der IOHandler Property zuweisen, Wie würde so eine Zuweisung aussehen? |
AW: XLM Payload als Post
Hallo,
meinst Du das so? "HTTP.IOHandler.AllData(nl);" +nl +nl und so weiter.......??
Delphi-Quellcode:
procedure TForm1.Button2Click(Sender: TObject);
var HTTP: TIdHTTP; RequestBody: TStream; ResponseBody,nl: 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('https://login.fireboard.net/api?authkey={123456789}&call=operation_data', RequestBody); HTTP.IOHandler.AllData(nl); // in etwa so? finally RequestBody.Free; end; except on E: EIdHTTPProtocolException do begin Showmessage(E.Message); Showmessage(E.ErrorMessage); end; on E: Exception do begin Memo1.Lines.Insert(0,(E.Message)+' '+FormatDateTime('hh:nn:ss',Now)); end; end; finally HTTP.Free; Memo1.Lines.Insert(0,'Zeitstempel '+ FormatDateTime('hh:nn:ss',Now)); end; end; |
AW: XLM Payload als Post
|
AW: XLM Payload als Post
Habe mir die Beispiele angesehen, mache ich doch!
Versehe ich nicht??
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('https://login.fireboard.net/api?authkey={123456789}&call=operation_data',RequestBody); // hier wird der Key doch übermittelt! finally RequestBody.Free; end; |
AW: XLM Payload als Post
Welches Delphi benutzt du?
Wäre es für dich eine Option ggf. auf Indy 10 zu aktualisieren? Dann hättest du das Problem nicht. |
AW: XLM Payload als Post
Habe Delphi XE7 :-)
|
AW: XLM Payload als Post
Da müsstest du doch Indy 10 haben, oder täusch ich mich?
Mach mal n ButtonClick() und
Delphi-Quellcode:
in die Uses
IdGlobal
Delphi-Quellcode:
var
HTTP: TIdHTTP; begin HTTP := TIdHTTP.Create; ShowMessage('Indy version: ' + http.Version); FreeAndNil(HTTP); |
AW: XLM Payload als Post
Hey
"idGlobal" ist drin! "Indoversion: 10.6.1.5182" |
AW: XLM Payload als Post
Aktualisere auf Version 10.6.2.XXX.
|
AW: XLM Payload als Post
Nein :shock:
habe sowas noch nicht gemacht :-( ist bestimmt wieder ein Riesen Ding! oder? |
AW: XLM Payload als Post
Nicht sonderlich, aber geht auch anders :-)
Nutze ![]() Ich komm gerade nicht zum Testen mit XE7, da ich das Windows 10.1 Update mach ;-) Edit Habe es getestet. Gibt Probleme. Gelöst durch ![]()
Code:
Grüße,
Win32/Debug
Stefan |
AW: XLM Payload als Post
Zitat:
- Indy herunterladen oder aus dem Subversion Repository auschecken - Die Verzeichnisse Lib\Code, Lib\Protocols und Lib\System dem Projekt-Suchpfad hinzufügen (damit ist sichergestellt, dass nur diese eine Projekt die neue Version verwendet) - kompilieren |
AW: XLM Payload als Post
Erstmal vielen Dank für die Hilfe!
aber der Hund liegt woanders begraben, immer noch die gleiche Meldung ;-( |
AW: XLM Payload als Post
Zitat:
|
AW: XLM Payload als Post
Kann dein "geht immer noch nicht" nicht nachvollziehen.
Delphi XE7
Delphi-Quellcode:
Einfach
unit Unit2;
interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IdHttp, IdSSLOpenSSL, Vcl.StdCtrls; type TForm2 = class(TForm) Button1: TButton; Memo1: TMemo; procedure Button1Click(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } end; var Form2: TForm2; implementation {$R *.dfm} procedure TForm2.Button1Click(Sender: TObject); var http: TIdHttp; params: TStringList; begin try http := TIdHTTP.Create(nil); params := TStringList.Create; http.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil); memo1.Text := http.Post('https://login.fireboard.net/api?authkey=blablablabla=&call=operationData', params); finally end; end; end.
Delphi-Quellcode:
auf das Formular und OnClick() beim Button das rein.
Button & Memo
Wenn du alles "richtig" gemacht hast, erhältst du als Antwort:
Code:
Wichtig
{"status":"error","errors":["unauthorized"]}
Hast du die beiden DLLs wie weiter oben beschrieben ins Verzeichnis zur Projekt-EXE gelegt? |
AW: XLM Payload als Post
Hallo Ihr lieben,
schönen Dank für Eure Hilfe, werde den Fehler bestimmt noch finden! Muss jetzt erstmal alles verstehen :) und testen! Vielleicht ist auch der Schüssel falsch? Mal schauen... Danke Danke Danke |
AW: XLM Payload als Post
Zitat:
|
AW: XLM Payload als Post
hallo mjustin,
funktioniert leider auch nicht :-( :( |
AW: XLM Payload als Post
hallo ZGD,
Code:
diese Meldung bekomme ich auch mit dem vorgegebenen Schlüssel!
{"status":"error","errors":["unauthorized"]}
Mir wurde bestimmt der falsche Schlüssel mitgeteilt! |
AW: XLM Payload als Post
Immerhin bist du der Lösung nahe :)
|
AW: XLM Payload als Post
Hallo,
also der Schlüssel ist korrekt! Ist die XML Formatierung in der StringList so richtig? Liegt vielleicht hier der Fehler?
Delphi-Quellcode:
function ExecuteAPI: string;
var http: TIdHttp; params: TStringList; begin try http := TIdHTTP.Create(nil); params := TStringList.Create; params.Add('<?xml version="1.0" encoding="UTF-8"?>'); params.Add('<fireboardOperation version="1.0">'); params.Add('<uniqueId>11202020</uniqueId>'); params.Add('<basicData>'); params.Add('<externalNumber>OF120131</externalNumber>'); params.Add('<keyword>F2/keyword>'); params.Add('<announcement>Wohnungsbrand</announcement>'); params.Add('<location>Test, Teststraße 1</location>'); params.Add('<geo_location>'); params.Add('</basicData>'); params.Add('</fireboardOperation>'); http.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil); Form3.Memo8.Lines.Insert(0,http.Post('https://login.fireboard.net/api?authkey=123456789=&call=operation_Data', params)+' ' + FormatDateTime ('dd.mm.yyyy , hh:nn:ss', Now)); finally params.Free; end; end; |
AW: XLM Payload als Post
Delphi-Quellcode:
Tag
function ExecuteAPI: string;
var http: TIdHttp; params: TStringList; begin try http := TIdHTTP.Create(nil); params := TStringList.Create; params.Add('<?xml version="1.0" encoding="UTF-8"?>'); params.Add('<fireboardOperation version="1.0">'); params.Add('<uniqueId>11202020</uniqueId>'); params.Add('<basicData>'); params.Add('<externalNumber>OF120131</externalNumber>'); params.Add('<keyword>F2/keyword>'); params.Add('<announcement>Wohnungsbrand</announcement>'); params.Add('<location>Test, Teststraße 1</location>'); params.Add('<geo_location>'); params.Add('</basicData>'); params.Add('</fireboardOperation>'); http.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil); Form3.Memo8.Lines.Insert(0,http.Post('https://login.fireboard.net/api?authkey=123456789=&call=operation_Data', params)+' ' + FormatDateTime ('dd.mm.yyyy , hh:nn:ss', Now)); finally params.Free; end; end;
Delphi-Quellcode:
wurde geöffnet, aber nicht geschlossen.
geo_location
|
AW: XLM Payload als Post
Zitat:
|
AW: XLM Payload als Post
Dass TStringList nicht für die Parameter verwendet werden darf hatte ich in Beitrag #6 ja bereits erwähnt. Auch fehlt das Encoding - es ist nur im XML, aber nicht im Request angegeben, dieser verwendet daher das Plattform-Encoding (ANSI).
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 17:27 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz