0

I'm using IdHTTP to execute php files on server. Worked fine for years. Suddenly getting 403 Forbidden errors with all my programs. Archived versions from year ago now fail also. Web host says they have changed nothing. To test, placed a simple php file that simply echoes a value on 3 separate host platforms (none SSL). Calls to all 3 fail with 403 error. If the url is placed in a browser address and called from there, call succeeds with expected value returned. Also tried running program connected via different ISPs. These failures just popped up in the last few days. Happens on many different computers.

Here is a very simple example that fails when sent to all 3 test servers

procedure TForm1.Button1Click(Sender: TObject);
var url: string;
  H: TIdHttp;
  SS: TStringStream;
begin
  url := 'http://www.somesite.com/test.php';
  H := TIdHttp.Create(nil);
  SS := TStringStream.Create;
  try
    H.Get(url, SS);
    Edit1.Text := SS.DataString;
  finally
    H.Free;
    SS.Free;
  end;
end;

Any help greatly appreciated.

  • HTTP programs don't just suddenly start failing after years of working fine. *SOMETHING* had to have changed on the server side, or on an intermediate server/proxy. Since a web browser works fine for you, I suggest you sniff the browser's HTTP traffic with a packet sniffer like Wireshark or Fiddler, or use the browser's own built-in debugger, and then configure `TIdHTTP` to mimic the same traffic. Chances are, the server doesn't like the HTTP headers that `TIdHTTP` is sending, such as the `User-Agent` header. So try changing that first (via the `TIdHTTP.Request.UserAgent` property). – Remy Lebeau Apr 10 '18 at 20:06
  • And FYI, you don't need the `TStringStream` at all, as `TIdHTTP` has an overload of `Get()` that returns the response content as a `String`, eg: `Edit1.Text := H.Get(url);` – Remy Lebeau Apr 10 '18 at 20:07
  • Thank you Remy. Did as you suggested and captured the User-Agent string with the Chrome debugger, set is with TIdHTTP.Request.UserAgent and recompiled. Everything seems to work now. It is somewhat disconcerting that all the past programs no longer work, but I'll deal with that as more issues arise. – Dave Fitzpatrick Apr 11 '18 at 19:43
  • A lot of web servers customize response content based on `User-Agent` (to account for differences in behavior between different clients/browsers), but such servers tend to not like Indy's default `User-Agent` as being an unknown app. That is why changing the `Request.UserAgent` to mimic a web browser usually works in cases like this – Remy Lebeau Apr 11 '18 at 20:07

0 Answers0