[Gambas-user] HTTP Form

T Lee Davidson t.lee.davidson at gmail.com
Tue May 17 00:20:00 CEST 2022


On 5/16/22 11:49, Gianluigi wrote:
> No, I don't mean 'opening the browser' but writing in the login form
> in order to access the site, otherwise what is the point of
> HttpForm.Add?

I didn't mean opening the browser either. I meant displaying the login form as a browser would. HttpForm is not designed to do 
that. It is not a graphical control.

The Form provided by gb.qt4 and the WebForm provided by gb.web.gui are graphical controls designed to parent other controls and 
display visually to the user.

HttpForm is merely a HTTP communication tool based on HttpClient. It displays nothing. It does not write into a form. It simply 
posts form data to a form submission handler.

The purpose of HttpForm.Add is to make it easier to format the data sent in the body of a POST operation. Look at the signature 
of HttpClient.Post:
Sub Post ( ContentType As String, Data As String [ , Headers As String[], TargetFile As String ] )

To submit a login name and a password to a form submission handler, based on this example, we would need to format the Data 
string as:
"login=myloginname&password=mypassword" ' Of course myloginname and mypassword should be the correct login credentials.

HttpForm makes it easy to craft that Data string using:
HttpForm.Add("login", "myloginname")
HttpForm.Add("password", "mypassword")


> if it were possible, I would appreciate an example where I have to
> respond in order to gain access and the code to do so:-P

If you want an application that will display a website's login form, allow you to fill it in & submit it, and then grant access 
if your credentials are correct, then use a web browser. Or, code something up with WebView (gb.qt5.webview). HttpForm will not 
do that.


 > If I reread what you write here
 >
 >> In this example, since the location of the page containing the form and the "action" URL are the same, the server determines
 >> whether to send the HTML form or to process the form data based on the HTTP method (ie. GET or POST) used by the client.
 >> HttpForm.Submit is a POST operation.
 >
 > It would be impossible to create in localhost a working example as I would like.
 >
 > Did I finally understand correctly what you had explained well, and
 > what I had not grasped on first reading?

No, I don't think you did. What I wrote above, which you quoted, would be true regardless of the location of the server (local 
or remote) as long as it used the same code.

What is impossible is: To create a working example, that will display an interactive login form from a website, using HttpForm - 
that is not its purpose.

What is possible is: To programmatically post login credentials, and login, to a website using HttpForm just as it is possible 
using HttpClient.


-- 
Lee


More information about the User mailing list