Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   TidHTTP post asmx und xml (https://www.delphipraxis.net/197990-tidhttp-post-asmx-und-xml.html)

jsp 25. Sep 2018 09:36

TidHTTP post asmx und xml
 
Hallo zusammen,

ich versuche ein xml von einem Server zu laden.
Die Beschreibung der Funktion (xml) findet ihr hier:
http://ifa17.test.crb.ch/partner/Par...op=downloadNPK

Bin neu auf dem Gebiet, und könnte ein paar Denkanstösse gebrauchen.
Versucht habe ich es so:

Delphi-Quellcode:
procedure TForm6.Button1Click(Sender: TObject);
var
  HTTP: TIdHTTP;
  RequestBody: TStringStream;
  res : string;
  xmlStr : TStrings;
begin
  xmlStr := TStringList.Create;
  xmlStr.Add('POST /partner/PartnerService17.asmx HTTP/1.1');
  xmlStr.Add('Host: ifa17.test.crb.ch');
  xmlStr.Add('Content-Type: text/xml; charset=utf-8');
  xmlStr.Add('Content-Length: 598');
  xmlStr.Add('SOAPAction: "http://www.crbnet.ch/crbox_partner/downloadNPK"');
  xmlStr.Add('<?xml version="1.0" encoding="utf-8"?>');
  xmlStr.Add('<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"');
  xmlStr.Add('xmlns:xsd="http://www.w3.org/2001/XMLSchema"');
  xmlStr.Add('xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">');
  xmlStr.Add('<soap:Body>');
  xmlStr.Add('<downloadNPK xmlns="http://www.crbnet.ch/crbox_partner">');
  xmlStr.Add('<chapter>501</chapter>');
  xmlStr.Add('<language>Deutsch</language>');
  xmlStr.Add('<year>2017</year>');
  xmlStr.Add('</downloadNPK>');
  xmlStr.Add('</soap:Body>');
  xmlStr.Add('</soap:Envelope>');
 
  Memo2.Clear;
  HTTP := TIdHTTP.Create;
  try
    try
      RequestBody := TStringStream.Create(xmlStr.Text, TEncoding.UTF8);
      try
        res := HTTP.Post('http://ifa17.test.crb.ch/partner/PartnerService17.asmx', RequestBody);
        (*
        Folgende Fehlermeldung wird dann ausgelöst:
        ---------------------------
        Im Projekt HTTP_Post.exe ist eine Exception der Klasse EIdHTTPProtocolException mit der Meldung
        'HTTP/1.1 500 Internal Server Error' aufgetreten.
        ---------------------------
        *)
        Memo2.Lines.Add('POST : '+res);
        res := HTTP.ResponseText;
        Memo2.Lines.Add('ResponseText : '+res);
      finally
        RequestBody.Free;
      end;
    except
      on E: EIdHTTPProtocolException do
      begin
        res := 'EIdHTTPProtocolException : '+E.Message + #13#10#13#10 + E.ErrorMessage;
        Memo2.Lines.Add(res);
      end;
      on E: Exception do
      begin
        res := 'Exception : '+E.Message;
        Memo2.Lines.Add(res);
      end;
    end;
  finally
    HTTP.Free;
    xmlStr.Free;
  end;
end;
Gruss, Jörn

Schokohase 25. Sep 2018 09:41

AW: TidHTTP post asmx und xml
 
Manchmal hilft es wenn man exakt arbeitet und nicht nur so ungefähr in etwa.

Doku sagt:
Code:
POST /partner/PartnerService17.asmx HTTP/1.1
Host: ifa17.test.crb.ch
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.crbnet.ch/crbox_partner/downloadNPK"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <downloadNPK xmlns="http://www.crbnet.ch/crbox_partner">
      <chapter>string</chapter>
      <language>Deutsch or Francais or Italiano or English</language>
      <year>int</year>
    </downloadNPK>
  </soap:Body>
</soap:Envelope>
Du machst
Code:
POST /partner/PartnerService17.asmx HTTP/1.1
Host: ifa17.test.crb.ch
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.crbnet.ch/crbox_partner/downloadNPK"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <downloadNPK xmlns="http://www.crbnet.ch/crbox_partner">
      <chapter>string</chapter>
      <language>Deutsch or Francais or Italiano or English</language>
      <year>int</year>
    </downloadNPK>
  </soap:Body>
</soap:Envelope>

Sherlock 25. Sep 2018 09:42

AW: TidHTTP post asmx und xml
 
Hast Du mal versucht über "Komponente -> WSDL importieren" die ganze Arbeit einfach Delphi zu überlassen?
Das WSDL liegt ja hier bereit: http://ifa17.test.crb.ch/partner/Par...ce17.asmx?WSDL

Sherlock

mjustin 25. Sep 2018 11:15

AW: TidHTTP post asmx und xml
 
Zitat:

Zitat von Schokohase (Beitrag 1414071)
Manchmal hilft es wenn man exakt arbeitet und nicht nur so ungefähr in etwa.

Doku sagt:
Code:
POST /partner/PartnerService17.asmx HTTP/1.1
Host: ifa17.test.crb.ch
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.crbnet.ch/crbox_partner/downloadNPK"

...
Du machst
Code:
POST /partner/PartnerService17.asmx HTTP/1.1
Host: ifa17.test.crb.ch
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.crbnet.ch/crbox_partner/downloadNPK"
...

Beides dürfte wenig Aussicht auf Erfolg haben: da TIdHTTP das POST /... und die Header sendet, muss man sie nicht in die Stringlist für den HTTP Body schreiben. Nur wenn man mit einem puren TCP Client HTTP Requests senden will, müssen diese Zeilen vor dem Body gesendet werden. TIdHTTP macht das komfortabel.

Schokohase 25. Sep 2018 11:27

AW: TidHTTP post asmx und xml
 
Zitat:

Zitat von mjustin (Beitrag 1414088)
Zitat:

Zitat von Schokohase (Beitrag 1414071)
Manchmal hilft es wenn man exakt arbeitet und nicht nur so ungefähr in etwa.

Doku sagt:
Code:
POST /partner/PartnerService17.asmx HTTP/1.1
Host: ifa17.test.crb.ch
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.crbnet.ch/crbox_partner/downloadNPK"

...
Du machst
Code:
POST /partner/PartnerService17.asmx HTTP/1.1
Host: ifa17.test.crb.ch
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.crbnet.ch/crbox_partner/downloadNPK"
...

Beides dürfte wenig Aussicht auf Erfolg haben: da TIdHTTP das POST /... und die Header sendet, muss man sie nicht in die Stringlist für den HTTP Body schreiben. Nur wenn man mit einem puren TCP Client HTTP Requests senden will, müssen diese Zeilen vor dem Body gesendet werden. TIdHTTP macht das komfortabel.

... und length bei Content-Length passt auch nicht ... und von daher sollte einleuchten, dass es sich hier um keine fertige Lösung handelt, sondern ein Hinweis: "Bitte nochmal anschauen, da passen so grundlegende Sachen noch gar nicht"

Sherlock 26. Sep 2018 09:25

AW: TidHTTP post asmx und xml
 
Wir sind zu schnell...

Sherlock

jsp 26. Sep 2018 09:36

AW: TidHTTP post asmx und xml
 
Oder ich zu langsam :roll:
Danke Sherlock, habe es mit WSDL importieren gelöst...

Sherlock 26. Sep 2018 12:15

AW: TidHTTP post asmx und xml
 
:thumb:

Freut mich! Danke für die Rückmeldung.

Sherlock


Alle Zeitangaben in WEZ +1. Es ist jetzt 22:56 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