TScHttpWebRequest does not redirect well

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
Post Reply
vinidf
Posts: 1
Joined: Fri 15 Jan 2021 11:39

TScHttpWebRequest does not redirect well

Post by vinidf » Fri 15 Jan 2021 12:22

Hello!

I'm trying to download a file from "https://www.cbr.ru/s/newbik" resource using TScHttpWebRequest component but it raises an exception "scNotFound".

Here's my code:

Code: Select all

procedure TForm1.Button3Click(Sender: TObject);
var
  vRequest: TScHttpWebRequest;
  vResponse: TScHttpWebResponse;
  vFile: TFileStream;
begin
  vRequest := TScHttpWebRequest.Create('https://www.cbr.ru/s/newbik');
  try
    vResponse := vRequest.GetResponse; // <-- exception raises here
    try
      vFile := TFileStream.Create('tmp.zip', fmCreate);
      vResponse.ReadToStream(vFile);
    finally
      vResponse.Free;
      vFile.Free;
    end;
  finally
    vRequest.Free;
  end;
end;
If you try to submit the same request using SoapUI application you can notice that there's a redirection to another address:
HTTP/1.1 301 Moved Permanently
...
Location: /Queries/XsltBlock/File/101478?fileId=0
...
And if you change URI in my samle code to this new location manually - all works well:

Code: Select all

procedure TForm1.Button3Click(Sender: TObject);
var
  vRequest: TScHttpWebRequest;
  vResponse: TScHttpWebResponse;
  vFile: TFileStream;
begin
  //vRequest := TScHttpWebRequest.Create('https://www.cbr.ru/s/newbik');
  vRequest := TScHttpWebRequest.Create('https://www.cbr.ru/Queries/XsltBlock/File/101478?fileId=0');
  try
    vResponse := vRequest.GetResponse;
    try
      vFile := TFileStream.Create('tmp.zip', fmCreate);
      vResponse.ReadToStream(vFile);
    finally
      vResponse.Free;
      vFile.Free;
    end;
  finally
    vRequest.Free;
  end;
end;
So it looks like there's something wrong with redirection in TScHttpWebRequest..
Is it possible to make this component do redirects automatically?

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: TScHttpWebRequest does not redirect well

Post by ViktorV » Mon 18 Jan 2021 16:35

Thank you for the information. The issue investigation is in progress. We will inform you when we have any results.

Post Reply