Forum > General
Help Needed With FPHTTPClient & Proxies...
(1/1)
AaronCatolico1:
Is it possible to use public or private proxies with the FPHTTPClient? If so, I'd like to see an example.
I've tried a variety of public proxies, especially socks5 proxies from sites such as:
* http://free-proxy.cz/en/proxylist/country/US/all/ping/all
* https://spys.one/en/socks-proxy-list
* https://proxyscrape.com/free-proxy-listetc.
The error messages I keep getting are "timed out" & "failed to connect", no matter whichever proxy & type I use.
Here's what I'm currently using & have tried:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Grids, ExtCtrls, ComCtrls, fphttpclient, openssl, opensslsockets; procedure TForm1.Button1Click(Sender: TObject);var HTTPClient: TFPHTTPClient; Response: TStringStream; URL, SearchTerm: string; ProxyHost, ProxyUser, ProxyPass: string; ProxyPort:integer;begin // Check if Edit1 (search box) is available and not empty if Edit1.Text <> '' then SearchTerm := Edit1.Text else begin ShowMessage('Please enter a search term.'); Exit; end; // Replace spaces in the search term with "+" for URL encoding SearchTerm := StringReplace(SearchTerm, ' ', '+', [rfReplaceAll]); // Construct the Google search URL URL := 'https://www.google.com/search?q=' + SearchTerm; // Proxy configuration ProxyHost := '127.0.0.1'; // Example proxy server address ProxyPort := 8080; // Example proxy port // Create HTTP client and response stream HTTPClient := TFPHTTPClient.Create(nil); Response := TStringStream.Create(''); try try // Set proxy settings HTTPClient.Proxy.Host := ProxyHost; HTTPClient.Proxy.Port := ProxyPort; // Optional: Set a user-agent header to mimic a browser HTTPClient.AddHeader('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'); // Perform the GET request HTTPClient.Get(URL, Response); // Display the fetched HTML in the TMemo Memo1.Lines.Text := Response.DataString; except on E: Exception do ShowMessage('An error occurred: ' + E.Message); end; finally // Free resources Response.Free; HTTPClient.Free; end;end;
Is the FPHTTPClient not built to use proxies? I haven't been able to find any examples online. AI is what helped me generate this code (as shown above).
I tried the code as shown above to no avail. I was expecting the FPHTTPClient to have proxy support, but not able to make any connections as described above.
Navigation
[0] Message Index