私のプログラムには次のコードがあります。プロキシが有効なプロキシであるかどうかを確認しようとすると、プログラムがクラッシュします。これを修正する方法はありますか?私はインディ10を使用しています。
if checkproxy('http://www.google.com') label1.text:='Good' else label1.text:='bad';
checkproxyを要求した後に別のidHTTP接続を呼び出そうとすると、プログラムがクラッシュします。
これは実際のコードです....エラーが返されます...
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;
エラーメッセージ:E001B844Aのモジュールkey.exeで例外AccessViolation。モジュール'key.exe'のアドレス005B844Aでのアクセス違反。アドレス00000000の読み取り。