How to download an html page after filling a form?

Hi all,

I’d like to download an html page but the page requires the visitor to fill in a html form first. I’m using REST’s TWebHTTPRequest to emulate it with POST method and an additional "Content-Type=application/x-www-form-urlencoded” headers. But it failed as if it sends nothing to the form. Is there a way to do it correctly?

It’s fine if I try it from ReqBin here.

Thank you.

Best regards,

Mr. Bee

What exact code do you use?
What exact response do you see in the browser console?

Here’s the code:

unit Unit1;

interface

uses
  System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
  WEBLib.Forms, WEBLib.Dialogs, WEBLib.StdCtrls, WEBLib.REST;

type
  TForm1 = class(TWebForm)
    WebButton1: TWebButton;
    WebMemo1: TWebMemo;
    WebHTTPRequest1: TWebHTTPRequest;
    procedure WebButton1Click(Sender: TObject);
    procedure WebHTTPRequest1Response(Sender: TObject; AResponse: string);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.WebHTTPRequest1Response(Sender: TObject; AResponse: string);
begin
  WebMemo1.Lines.Add(AResponse);
end;

procedure TForm1.WebButton1Click(Sender: TObject);
begin
  WebHTTPRequest1.Execute;  
end;

end. 

Here’s the form:


Here’s the result:

Is there something wrong?

When you inspect the browser console, you can see the reason:

This means the HTTP resource is not enabled for CORS.

For a background on CORS, please see:

But why a request from reqbin is allowed?

Could we override the request origin by setting it in the headers? I’ve tried it but it failed. Perhaps there is some other things I need to do as well?

  1. reqbin is doing the request server side , you can verify this inspecting your network tab in the browser console
  2. CORS is a server side config, this cannot be workarounded client-side. Please study what CORS is https://www.codecademy.com/articles/what-is-cors