I have the following code in my program. When I try to check if the proxy is a valid proxy or not it crashes my program. Any ideas how to fix this? I'm using indy 10.
if checkproxy('http://www.google.com') label1.text:='Good' else label1.text:='bad';
If I try to call another idHTTP connect after requesting checkproxy it crashes the program.
This is the actual code.... That returns the error...
function TregForm.webSession(sURL : ansistring) : ansistring;
var sstream : Tstringstream;
httpcon : TIdHTTP;
antifreeze : TIdAntiFreeze;
begin
result := '';
sstream := tstringstream.Create('');
try
if length(SettingsForm.edtProxyServer.text) >= 7 then // 0.0.0.0
if checkproxy('http://www.google.com') then
begin
antifreeze := TIdAntiFreeze.Create(nil);
httpcon := TIdHTTP.create;
httpcon.ProxyParams.BasicAuthentication:=true;
httpcon.ProxyParams.ProxyPassword:=SettingsForm.edtProxyPass.Text;
httpcon.ProxyParams.ProxyPort:=strtoint(SettingsForm.edtProxyPort.Text);
httpcon.ProxyParams.ProxyServer:=SettingsForm.edtProxyServer.Text;
httpcon.ProxyParams.ProxyUsername:=SettingsForm.edtProxyUserName.Text;
end
else
begin
showmessage('Proxy Server Not Working.. Attempting to bypass the Proxy');
antifreeze := TIdAntiFreeze.Create(nil);
httpcon := TIdHTTP.create;
//httpcon.Request.ProxyConnection:='';
//httpcon.ProxyParams.BasicAuthentication:=false;
//httpcon.ProxyParams.ProxyPassword:='';
//httpcon.ProxyParams.ProxyPort:=0;
//httpcon.ProxyParams.ProxyServer:='';
//httpcon.ProxyParams.ProxyUsername:='';
end;
httpcon.HandleRedirects := true;
antifreeze.Active := true;
HttpCon.Get(sURL,sstream);
result := utf8towidestring(sstream.DataString);
except
httpcon.Disconnect;
end;
antifreeze.Active := false;
freeandnil(httpcon);
freeandnil(antifreeze);
freeandnil(sstream);
end;
function TregForm.checkproxy(sURL : ansistring) : boolean;
var //sstream : Tstringstream;
httpcon : TIdHTTP;
antifreeze : TIdAntiFreeze;
begin
result := true;
try
antifreeze := TIdAntiFreeze.Create(nil);
httpcon := TIdHTTP.create;
//sstream := tstringstream.Create('');
httpcon.ProxyParams.BasicAuthentication:=true;
httpcon.ProxyParams.ProxyPassword:=SettingsForm.edtProxyPass.Text;
httpcon.ProxyParams.ProxyPort:=strtoint(SettingsForm.edtProxyPort.Text);
httpcon.ProxyParams.ProxyServer:=SettingsForm.edtProxyServer.Text;
httpcon.ProxyParams.ProxyUsername:=SettingsForm.edtProxyUserName.Text;
httpcon.HandleRedirects := true;
antifreeze.Active := true;
HttpCon.Request.ProxyConnection:=SettingsForm.edtProxyServer.Text;
HttpCon.head(sURL);
httpCon.Disconnect;
except
on E: EIdException do begin
result:=false;
end;
On E:exception do begin
//showmessage('External error:' + #13#10 + E.Message);
showmessage('Proxy Settings Error');
result:=false;
end;
end;
antifreeze.Active := false;
freeandnil(httpcon);
freeandnil(antifreeze);
//freeandnil(sstream);
end;
Error mesage: Exception AccessViolation in module key.exe at E001B844A. Access violation at address 005B844A in module 'key.exe'. Read of address 00000000.