![]() |
AW: Proxy-Einstellungen automatisch erkennen mit IDHttp
Es ist echt zum Haare raufen
ich bekomme das aufgrund fehlender Beispiele echt nicht gebacken :( Kennt sich jemand mit WinINET aus? ..evtl würde ich von indy weg auf win.init wechselen. Allerdings bräuchte ich auch hier ein Beispiel. lG M |
AW: Proxy-Einstellungen automatisch erkennen mit IDHttp
Ein Beispiel wofür?
Delphi-Quellcode:
Das Herunterladen mal grob skizziert:
FInternetHandle := InternetOpenA('MyAppUserAgent', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
Delphi-Quellcode:
function TpkInternetHTTP.Download(Server, Path: AnsiString; Stream: TStream): boolean;
var hSession, hRequest: TInternetHandle; dwConnIC, dwConnHOR, dwSize, dwIndex: DWord; iEC: integer; pc: PAnsiChar; buf: string[32]; wPort: Word; sPort: AnsiString; begin Result := false; FCurrentBytes := 0; FTotalBytes := 0; FErrorCode := 0; // InternetConnect dwConnIC := 0; wPort := INTERNET_DEFAULT_HTTP_PORT; if Pos(':', Server) > 0 then begin sPort := Server; Delete(sPort, 1, Pos(':', sPort)); SetLength(Server, Length(Server) - Length(sPort) - 1); wPort := StrToIntDef(sPort, INTERNET_DEFAULT_HTTP_PORT); end; hSession := InternetConnectA(FInternetHandle, PAnsiChar(Server), wPort, nil, nil, INTERNET_SERVICE_HTTP, 0, dwConnIC); if hSession = 0 then begin FErrorCode := GetLastError; Exit; end; try // HttpOpenRequest dwConnHOR := 0; hRequest := HttpOpenRequestA(hSession, nil, PAnsiChar(Path), nil, nil, nil, INTERNET_FLAG_RELOAD or INTERNET_FLAG_NO_CACHE_WRITE, dwConnHOR); if hRequest = 0 then begin FErrorCode := GetLastError; Exit; end; try // HttpSendRequest dwSize := 0; if HttpSendRequestA(hRequest, nil, 0, nil, 0) then begin // HttpQueryInfo - status SetLength(buf, 32); dwSize := Length(buf); dwIndex := 0; if HttpQueryInfoA(hRequest, HTTP_QUERY_STATUS_CODE, buf[1], dwSize, dwIndex) then begin Val(Copy(buf, 1, dwSize), FStatusCode, iEC); if iEC > 0 then begin FStatusCode := 0; // TODO : error handling end; end else begin FStatusCode := 0; // TODO : error handling end; if (FStatusCode = 404) then begin FErrorCode := ERROR_NO_MORE_FILES; Exit; end; // HttpQueryInfo - length SetLength(buf, 32); dwSize := Length(buf); dwIndex := 0; if HttpQueryInfoA(hRequest, HTTP_QUERY_CONTENT_LENGTH, buf[1], dwSize, dwIndex) then begin Val(Copy(buf, 1, dwSize), FTotalBytes, iEC); if iEC > 0 then begin FTotalBytes := 0; // TODO : error handling here end; end else begin FTotalBytes := 0; // TODO : error handling here end; GetMem(pc, FBlockSize + 1); try repeat if InternetReadFile(hRequest, pc, FBlockSize, dwSize) then begin Stream.WriteBuffer(pc^, dwSize); Inc(FCurrentBytes, dwSize); // FireProgress; end else dwSize := 0; until dwSize = 0; // FireProgress; finally FreeMem(pc); end; // FireProgress; Result := true; end else begin FErrorCode := GetLastError; end; finally InternetCloseHandle(hRequest); end; finally InternetCloseHandle(hSession); end; Stream.Seek(0, soFromBeginning); end; |
AW: Proxy-Einstellungen automatisch erkennen mit IDHttp
Und die WinInet-Referenz findet man
![]() |
AW: Proxy-Einstellungen automatisch erkennen mit IDHttp
Ich bin generell niemand der erwartet alles "ins nest gelegt zu bekommen".
ich kann nur folgendes sagen: wer sich mal auf die WWW-recherche zum Thema "NTLM" macht wird viele Fragen, (Fehl)Versuche, etc finden allerdings aber wenige (keine?) echten Hilfen und v.a. keine "ja ich hab's geschafft und zwar so" Informationen. Das gilt übrigens auch für die Indy-entwickler selbst. Aber ich lasse mich gerne eines besseren belehren. Meine eigenen Bemühungen diesbzgl. muss ich wohl leider einfrieren :oops:. Das Thema ist einfach ziemlich speziell bzw. komplex und/oder "ich bin dafür einfach programmierseitig nicht gut genug" bzw. kann derzeit nicht die dafür notwendige Energie einfliessen lassen. |
AW: Proxy-Einstellungen automatisch erkennen mit IDHttp
Wer bis hier gelesen hat sollte vielleicht
![]() |
AW: Proxy-Einstellungen automatisch erkennen mit IDHttp
Ich habe mich heute nochmal an das Thema gemacht.
Good news: inzwischen funktioniert IDHTTP bei mir auf einem NTML authentifiziertem Proxy-Server! Der Code sollte ebenso "Digest" und "Basic" Proxy Authentifizierung beherrschen, was ich aber in Ermangelung eines entsprechenden Proxies noch nicht austesten konnte. Was ist zu tun: - Ein IDHTTP Element auf das Form legen - Ein IdSSLIOHandlerSocketOpenSSL auf das Form legen - Beim IDHTTP Element im IOHandler "IdSSLIOHandlerSocketOpenSSL" auswählen - Folgende evtl. noch fehlenden Anweisungen in die Uses Klausel aufnehmen: IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdAuthenticationSSPI , IdAuthentication , IdAuthenticationDigest , IdHeaderList, IdIOHandler, IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL ; - URL und Port des Proxies irgendwo übergeben (uB in FormCreate)
Delphi-Quellcode:
IdHTTP1.ProxyParams.ProxyServer := 'MyProxyServer';
IdHTTP1.ProxyParams.ProxyPort := 'MyProxyPort'; - Folgendes in IdHTTPMainSelectProxyAuthorization aufnehmen
Delphi-Quellcode:
procedure TForm1.IdHTTPMainSelectProxyAuthorization(Sender: TObject; var AuthenticationClass: TIdAuthenticationClass; AuthInfo: TIdHeaderList);
begin // First check for NTLM authentication, as you do not need to set username and password because Indy will automatically // handle passing your Windows Domain username and password to the proxy server if (pos('Proxy-Authenticate: NTLM', IdHTTPMain.Response.RawHeaders.Text)>0) then begin IdHTTP1.ProxyParams.BasicAuthentication := false; AuthenticationClass := TIdSSPINTLMAuthentication; end else begin //Next check for Basic if (pos('Proxy-Authenticate: Basic', IdHTTP1.Response.RawHeaders.Text)>0) then begin AuthenticationClass := TIdBasicAuthentication; IdHTTP1.ProxyParams.BasicAuthentication := true; end else begin // Then Digest if (pos('Proxy-Authenticate: Digest', IdHTTPMain.Response.RawHeaders.Text)>0) then AuthenticationClass := TIdDigestAuthentication end; //.------------ IdHTTP1.ProxyParams.ProxyUsername := 'YourUsername'; IdHTTP1.ProxyParams.ProxyPassword := 'YourPassword'; end; end; - Get-Funktion aufrufen um etwas zu machen. Z.B.
Delphi-Quellcode:
Viel Spaß
Memo1.Lines.Text := IdHTTP1.Get('http://www.google.de');
Martin |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:05 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