C
C
Chvalov2014-09-28 16:58:56
Delphi
Chvalov, 2014-09-28 16:58:56

How to send a POST request via idhttp to a site loaded in WebBrowser1 in Delphi ?

Hello, how to send a post request to a site that has loaded in WebBrowser1 without reloading the page!
There is a code:

procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate(Edit1.Text);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
Doc:IHTMLDocument2;
S:string;
begin
while WebBrowser1.ReadyState<READYSTATE_COMPLETE do
begin
while WebBrowser1.Busy do Application.ProcessMessages;
end;
Doc:= WebBrowser1.Document as IHTMLDocument2;
s:=doc.body.innerHTML;
Memo1.Text:=s;
end;
Button1 - Loads the site Button2
- Displays its source with the executed js script where I can see that I need to send a post request

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AlexP11223, 2014-09-28
@AlexP11223

No way, IdHttp and WebBrowser don't know anything about each other.
You can try to take Cookies from there and use them to request in IdHttp (this will not affect WebBrowser in any way).
Or, in the WebBrowser, press (programmatically, using its methods and / or JavaScript execution) the necessary buttons on the site, etc., which will perform the necessary actions. Or using AJAX to make a request in itself.
Or do not use WebBrowser at all initially, but figure out what this JS code does and do the same.

while WebBrowser1.ReadyState<READYSTATE_COMPLETE do
begin
while WebBrowser1.Busy do Application.ProcessMessages;
end;

Why block the UI thread so severely? There is also a download completion event.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question