Get IE proxy settings for the Http client component

Download source code

See also Get IE proxy settings

The sample program sets the system IE proxy settings to the Http client component, including Http, Https and Socks.

procedure TForm1.GetIEProxySettings(AList: TStrings);
var
  pInfo: PInternetProxyInfo;
  len: DWORD;
begin
  AList.Clear();
 
  len := 0;
  InternetQueryOption(nil, INTERNET_OPTION_PROXY, nil, len);
  if (len > 0) then
  begin
    GetMem(pInfo, len);
    try
      if InternetQueryOption(nil, INTERNET_OPTION_PROXY, pInfo, len) then
      begin
        SplitText(string(pInfo.lpszProxy), AList, ' ');
      end;
    finally
      FreeMem(pInfo);
    end;
  end;
end;

 

 

procedure TForm1.btnGetIEProxyClick(Sender: TObject);
var
  proxyList: TStrings;
  proxy: string;
  url: TclUrlParser;
begin
  proxyList := TStringList.Create();
  try
    GetIEProxySettings(proxyList);
 
    if cbProxyType.ItemIndex = 0 then
    begin
      url := TclUrlParser.Create();
      try
        url.Parse(edtUrl.Text);
 
        if (url.UrlType = utHTTPS) then
        begin
          proxy := proxyList.Values['https'];
        end else
        begin
          proxy := proxyList.Values['http'];
        end;
      finally
        url.Free();
      end;
    end else
    begin
      proxy := proxyList.Values['socks'];
    end;
 
    if WordCount(proxy, [':']) > 1 then
    begin
      edtProxyServer.Text := ExtractWord(1, proxy, [':']);
      edtProxyPort.Text := ExtractWord(2, proxy, [':']);
    end else
    begin
      edtProxyServer.Text := proxy;
      edtProxyPort.Text := '8080';
    end;
  finally
    proxyList.Free();
  end;
end;

 

 

Add Feedback