Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Delphi Indy10 IdHTTP und WebClient (https://www.delphipraxis.net/151125-indy10-idhttp-und-webclient.html)

dh-clfs 6. Mai 2010 14:52


Indy10 IdHTTP und WebClient
 
Hallo zusammen,

Ziel ist mit der Anwendung ein Webservice zu nutzen, der erst nach Anmeldung an der ASP-Website erreichbar ist.
Die Anmeldung mittels TIdHTTP funktioniert wunderbar. Liefert mir die SessionID auch an den CookieManager zurück.

Auch der WebClient an sich funktioniert, jedoch eröffnet er eine neue Instanz. Ich habe bereits mehrere Webseiten durchsucht wie ich die bereits durch TIdHTTP genutzte Session an den WebClient übergeben kann.

Delphi-Quellcode:
...
interface
...
uses
...,IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, IdCookieManager,
...
implementation

uses webservice;
...

  procedure TForm1.est1Click(Sender: TObject);
  var
  response : tStringstream;
  CookieManager : TidCookiemanager;
  ws: WebService_x0020_for_x0020_Updating_x0020_Soap;
  begin
    idhttp1.Create(nil);
    CookieManager := tidcookiemanager.create(nil);
    idhttp1.AllowCookies := true;
    idhttp1.CookieManager := CookieManager;
    idhttp1.Request.Connection := 'Keep-Alive';
    idhttp1.Request.ContentType := 'application/x-www-form-urlencoded';
    idhttp1.request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)';
    idhttp1.HandleRedirects := true;
    try
      idhttp1.get(myURL+'/login.aspx?psw'+MyPassword+'&usr'+MyUser, response);
      if pos('welcome.aspx',response.DataString) = 0 then Showmessage('Login failed')
       else begin
        ws := GetWebService_x0020_for_x0020_Updating_x0020_Soap(true);
        ws.CleanUp;
      end;
    finally
      response.Free;
      idhttp1.Free;
    end;
  end;
Hat jemand eine Idee?

Vielen Dank im Voraus.

mjustin 6. Mai 2010 16:41

Re: Indy10 IdHTTP und WebClient
 
Delphi-Quellcode:
  ws: WebService_x0020_for_x0020_Updating_x0020_Soap;
Das läßt auf einen Soap Service schliessen, daher würde ich zuerst versuchen den Web Service WSDL Importer und die HTTPRio Komponente zu benutzen. Funktioniert manchmal, aber nicht immer - ist aber in den funktionierenden Fällen einfacher in der Handhabung.

Hope this helps,

dh-clfs 6. Mai 2010 16:59

Re: Indy10 IdHTTP und WebClient
 
Danke für die schnelle Antwort.

Der WebService ist über WSDL importiert worden und die Unit von WebService ist eingebunden.

Delphi-Quellcode:
unit webservice;

interface

uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;

const
  IS_OPTN = $0001;
  IS_REF = $0080;


type

  // ************************************************************************ //
  // Die folgenden Typen, auf die im WSDL-Dokument Bezug genommen wird, sind in dieser Datei
  // nicht repräsentiert. Sie sind entweder Aliase(@) anderer repräsentierter Typen oder auf sie wurde Bezug genommen,
  // aber in diesem Dokument nicht deklariert (!). Die Typen aus letzterer Kategorie
  // sind normalerweise mit vordefinierten/bekannten XML- oder Borland-Typen verbunden; sie könnten aber auch ein Anzeichen
  // für ein falsches WSDL-Dokument sein, das einen Schema-Typ nicht deklariert oder importiert.. // ************************************************************************ //
  // !:string         - "http://www.w3.org/2001/XMLSchema"[Gbl]
  // !:int            - "http://www.w3.org/2001/XMLSchema"[Gbl]



  // ************************************************************************ //
  // Namespace : [url]http://www.x.net/[/url]
  // soapAction: [url]http://www.x.net/%operationName%[/url]
  // Transport : [url]http://schemas.xmlsoap.org/soap/http[/url]
  // Stil    : document
  // Bindung  : WebService_x0020_for_x0020_Updating_x0020_Soap
  // Service  : WebService_x0020_for_x0020_Updating_x0020_
  // Port     : WebService_x0020_for_x0020_Updating_x0020_Soap
  // URL      : [url]http://x/webservice.asmx[/url]
  // ************************************************************************ //
  WebService_x0020_for_x0020_Updating_x0020_Soap = interface(IInvokable)
  ['{BE7B6088-D764-E211-4739-7232AB55E793}']
    function CleanUp: WideString; stdcall;
    function SQLAddMain(const Param1: Integer; const Param2: WideString; const Param3: WideString; const Param4: WideString; const param5: WideString; const Param6: WideString;
                         const Param7: WideString; const Param8: WideString; const Param9: WideString; const ParamA: WideString; const ParamB: WideString;
                         const ParamC: Integer; const ParamD: Integer): WideString; stdcall;
    function SQLAddContent(const Param1: Integer; const Param2: Integer; const Param3: WideString; const Param4: WideString; const Param5: WideString): WideString; stdcall;
    function SQLAddRelations(const Param1: Integer; const Param2: Integer; const Param3: Integer): WideString; stdcall;
  end;

function GetWebService_x0020_for_x0020_Updating_x0020_Soap(UseWSDL: Boolean=System.False; Addr: string='http://x/WebService.asmx'; HTTPRIO: THTTPRIO = nil): WebService_x0020_for_x0020_Updating_x0020_Soap;


implementation
  uses SysUtils;

function GetWebService_x0020_for_x0020_Updating_x0020_Soap(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): WebService_x0020_for_x0020_Updating_x0020_Soap;
const
  defWSDL = 'C:\webservice.xml';
  defURL = 'http://x/webservice.asmx';
  defSvc = 'WebService_x0020_for_x0020_Updating_x0020_';
  defPrt = 'WebService_x0020_for_x0020_Updating_x0020_Soap';
var
  RIO: THTTPRIO;
begin
  Result := nil;
  if (Addr = '') then
  begin
    if UseWSDL then
      Addr := defWSDL
    else
      Addr := defURL;
  end;
  if HTTPRIO = nil then
    RIO := THTTPRIO.Create(NIL)
  else
    RIO := HTTPRIO;
  try
    Result := (RIO as WebService_x0020_for_x0020_Updating_x0020_Soap);
    if UseWSDL then
    begin
      RIO.WSDLLocation := Addr;
      RIO.Service := defSvc;
      RIO.Port := defPrt;
    end else
      RIO.URL := Addr;
  finally
    if (Result = nil) and (HTTPRIO = nil) then
      RIO.Free;
  end;
end;


initialization
  InvRegistry.RegisterInterface(TypeInfo(WebService_x0020_for_x0020_Updating_x0020_Soap), 'http://www.x.net/', 'utf-8');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(WebService_x0020_for_x0020_Updating_x0020_Soap), 'http://www.x.net/%operationName%');
  InvRegistry.RegisterInvokeOptions(TypeInfo(WebService_x0020_for_x0020_Updating_x0020_Soap), ioDocument);

end.
Ich habe schon versucht über THTTPRIO an TidHTTP anzuknüpfen, bzw. vorweg die gleichen Aktionen durchzuführen wie mit TIdHTTP um mich an der Website anzumelden. Bin dort aber nicht wirklich weitergekommen weil die entsprechenden Eigenschaften und Methoden fehlen bze. ich diese nicht ersehe.

dh-clfs 7. Mai 2010 19:43

Re: Indy10 IdHTTP und WebClient
 
Gibt es eine Möglichkeit ide bereits erhaltene ASP-SessionID an HTTPrio zu übergeben?


Alle Zeitangaben in WEZ +1. Es ist jetzt 02:40 Uhr.

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