idHttp und Verwendung der URL
Hallo
Ich habe eine Download Programm mit der idHttp Kompo, das einwandfrei seit langem funktioniert solange ich bei der URL den vollen Namen verwende. Will ich aber jetzt eine IP Addresse verwenden, weil der Server z.B. keinen DNS Eintrag hat, bekomme ich eine Allgemeine Schutzverletzung. Also:
Code:
geht einwandfrei
internetForm.idHTTP1.Head('http://myServer.de/customers/cycles/meineDatei.cfg')
nicht aber
Code:
und produziert eine Schutzverletzung
internetForm.idHTTP1.Head('http:// 78.47.15.67/customers/cycles/meineDatei.cfg')
lasse ich die Datei weg, verwende also testweise nur:
Code:
läuft die Zeile ohne Schutzverletzung durch.
internetForm.idHTTP1.Head('http:// 78.47.15.67);
Hat jemand eine Idee dazu ?? vielen Dank |
AW: idHttp und Verwendung der URL
Ich habe keine Ahnung ob es daran liegt.
Aber nach http:// und der 7 ist ein Leerzeichen. |
AW: idHttp und Verwendung der URL
Es wäre interessant zu wissen, welche Exception genau geschmissen wird. Die Indys verraten eigentlich immer Recht genau, was das Problem war.
|
AW: idHttp und Verwendung der URL
Ich hoffe das Leerzeichen in der URL ist nur ein Copy&Paste Fehler zum Eintrag ins Forum.
Folgender Codeschnippsel zeigt Dir die Fehlermeldung an (Bei mir ist kein ShowMessage im Einsatz sondern ein Logfile Manager). Ausserdem habe ich eine Funktion um einen Zufallspfad und Dateinamen zu generieren, aber ich denke den Sinn der Funktion ergibt sich und vielleicht hilft es Dir ja:
Delphi-Quellcode:
// === Get a filepath from HTTP ================================================
function GetHTTPfile(AQuery,AUser,APassword:String; var AResponseText:String; var AResponseCode:Integer; var AMimeType:String) : String; // uses idHTTP, IdSSLOpenSSL, idURI, IdException, IdStack, // System.SysUtils, System.StrUtils, Classes var IdHTTP1 : TidHTTP; LHandler : TIdSSLIOHandlerSocketOpenSSL; lStream: TStringStream; httpGetString, sFilename : String; NewGUID: TGUID; begin IdHTTP1 := TIdHTTP.Create(nil); IdHTTP1.Request.UserAgent := 'Mozilla/3.0 (compatible; Indy Library)'; lStream := TStringStream.Create(Result); with IdHTTP1 do begin LHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil); IOHandler := LHandler; ReadTimeout := 30000; // OnWork := // Add here event handler // OnWorkBegin := // Add here event handler // = Check for authentification if (length(AUser) < 1) or (length(APassword) < 1) then Request.BasicAuthentication := False else begin Request.BasicAuthentication := true; HTTPOptions := HTTPOptions +[hoInProcessAuth]; Request.Username := AUser; Request.Password := APassword; end; httpGetString := TIdURI.URLDecode(AQuery); httpGetString := TIdURI.URLEncode(httpGetString); try WriteLog(1,'HTTP','URL=' +httpGetString); IdHTTP1.Get(TIdURI.URLEncode(httpGetString), lStream); AResponseCode := IdHTTP1.ResponseCode; AResponseText := IdHTTP1.ResponseText; AMimeType := IdHTTP1.Response.ContentType; lStream.Position := 0; CreateGUID(NewGUID); sFilename := GUIDToString(NewGUID); sFilename := // -> Put here estimated temporary filepath lStream.SaveToFile(sFilename); Result := sFilename; except on E: EIdHTTPProtocolException do begin AResponseCode := IdHTTP1.ResponseCode; AResponseText := IdHTTP1.ResponseText; ShowMessage('[ERROR] ' +'Indy raised a protocol error!' +' | ' +'HTTP status code: ' + IntToStr(E.ErrorCode) +' | ' +'Error message' + E.Message); end; on E: EIdConnClosedGracefully do begin AResponseCode := IdHTTP1.ResponseCode; AResponseText := IdHTTP1.ResponseText; ShowMessage('[ERROR] ' +'Indy reports, that connection was closed gracefully!'); end; on E: EIdSocketError do begin AResponseCode := IdHTTP1.ResponseCode; AResponseText := IdHTTP1.ResponseText; ShowMessage('[ERROR] ' +'Indy raised a socket error!' +' | ' +'Error code: ' + IntToStr(E.LastError) +' | ' +'Error message' + E.Message); end; on E: EIdException do begin AResponseCode := IdHTTP1.ResponseCode; AResponseText := IdHTTP1.ResponseText; ShowMessage('[ERROR] ' +'Indy raised an exception!' +' | ' +'Exception class: ' + E.ClassName +' | ' +'Error message: ' + E.Message); end; on E: Exception do begin AResponseCode := IdHTTP1.ResponseCode; AResponseText := IdHTTP1.ResponseText; ShowMessage('[ERROR] ' +'A non-Indy related exception has been raised!'); end; end; end; {httpclient} LHandler.Free; IdHTTP1.Disconnect; IdHTTP1.Free; FreeAndNil(lStream); end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:56 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