Einzelnen Beitrag anzeigen

jsp

Registriert seit: 9. Aug 2003
50 Beiträge
 
#1

TidHTTP post asmx und xml

  Alt 25. Sep 2018, 09:36
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
  Mit Zitat antworten Zitat