* * *

Author Topic: action= in html form to return response to calling browser?  (Read 1175 times)

epergola

  • Full Member
  • ***
  • Posts: 129
action= in html form to return response to calling browser?
« on: October 06, 2017, 03:09:37 am »
HI

I have an synapse http server in my PC.
I have a welcome page that comes up on the browser when someone type in the browser the IP of my router.
The welcome page asks for a code and a password.
When the synapse server receives this info, it validates it, and if it is ok it produces a simple html file that sends back.
I have the problem with the SEND BACK. In the form I have method = POST action = 192.x.x.x (my local IP).
When I use the browser from my own PC (and put the local IP) it works fine. I guess because in the html form (the welcome page)
I have method = POST action = 192.x.x.x (my local IP).
I suppose if I change that to the IP of the router, then the response (html) will be shown on the celular that makes the request.
BUT I need to put this on differente sites and I do not know their router IP. Any suggestion on what to put on action=? so that the
response is shown on the browser that sent the request?


GetMem

  • Hero Member
  • *****
  • Posts: 2463
Re: action= in html form to return response to calling browser?
« Reply #1 on: October 06, 2017, 06:26:25 am »
@epergola
Quote
I have an synapse http server in my PC.
I have a welcome page that comes up on the browser when someone type in the browser the IP of my router.
The welcome page asks for a code and a password.
When the synapse server receives this info, it validates it, and if it is ok it produces a simple html file that sends back.
I have the problem with the SEND BACK. In the form I have method = POST action = 192.x.x.x (my local IP).
When I use the browser from my own PC (and put the local IP) it works fine. I guess because in the html form (the welcome page)
I have method = POST action = 192.x.x.x (my local IP).
I suppose if I change that to the IP of the router, then the response (html) will be shown on the celular that makes the request.
BUT I need to put this on differente sites and I do not know their router IP. Any suggestion on what to put on action=? so that the
response is shown on the browser that sent the request?

Why do you want to send the client IP? Since you did a POST request, the server already know the address. The real issue is how can you make the local server visible to users located outside your router.  To achieve this you need to do a port forwarding combined with a dynamic DNS. So instead of your constantly changing IP, the user will type something like this: http://epergola.no-ip.org

epergola

  • Full Member
  • ***
  • Posts: 129
Re: action= in html form to return response to calling browser?
« Reply #2 on: October 06, 2017, 06:54:09 am »
Thanks Getmem.
The ever changing IP is only for testing purpose. Obviously When all is working alright it will use a dynamic DNS.

If you want to help me further, I attach the html I am using (I change teh ext. to txt for uploading).
The way it is, the synapse http server receives the GET first, then it submits the username + password results, then I produce a response in an html format that i want to sent back to the browser that did the
request.

To make it work from any browser outside my PC and router, what should I put in the ACTION? (I repeat i have port 81 forwarded and I know what is the IP of my router at a given moment, for testing). Thanks again

epergola

  • Full Member
  • ***
  • Posts: 129
Re: action= in html form to return response to calling browser?
« Reply #3 on: October 06, 2017, 07:29:07 am »
Some further details.
I do not want to send action to a php file o any other external program.
The httpserver contains all the code.
For example if in the remote browser someone type the IP address (or DNS) followed by :port_numbe /dothis
the httpserver execute the code to produce the response for "dothis" and send it back to the browser.
This for reasons of speed.

GetMem

  • Hero Member
  • *****
  • Posts: 2463
Re: action= in html form to return response to calling browser?
« Reply #4 on: October 06, 2017, 07:54:43 am »
Quote
The way it is, the synapse http server receives the GET first, then it submits the username + password results, then I produce a response in an html format that i want to sent back to the browser that did the request.
Usually after a successfully login the user is redirected to another html/php. If redirection is not an option, then right after you submit back the username+password result, send the html as a stream. In the response header specify Content-type as  text/html. Take a look at this example(ok it's indy not synapse + the response is a JSON but you get the idea): http://forum.lazarus.freepascal.org/index.php/topic,32771.0.html . I'm 100% convinced something similar exists in synapse(like AResponseInfo.ContentStream). I never used that component myself, so I cannot give you specific advice on how to implement the code.

« Last Edit: October 06, 2017, 08:03:11 am by GetMem »

epergola

  • Full Member
  • ***
  • Posts: 129
Re: action= in html form to return response to calling browser?
« Reply #5 on: October 06, 2017, 08:12:11 am »
Thanks again Getmeme.
Yes the same method exists in synapse.
My problem is with this part in the welcomepage.html
<form method="POST" action="http://192.168.1.67:80">
Username: <input type="PASSWORD" size="6" name="code"><br>
Password: <input type="PASSWORD" size="6" name="pass">
  <br><br>
  <input type="submit" value="Submit">
</form>
How should I change that? that "action" part. Coulc you help me ?
If not I still appreciate your help. you have done enough.

Leledumbo

  • Hero Member
  • *****
  • Posts: 7743
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: action= in html form to return response to calling browser?
« Reply #6 on: October 06, 2017, 09:10:09 am »
If the action handler comes from the same domain/ip (with the one that serves the login form), just use / for the action. HTML standard already defines that (relative URL means the URL is relative to the host).

epergola

  • Full Member
  • ***
  • Posts: 129
Re: action= in html form to return response to calling browser?
« Reply #7 on: October 06, 2017, 09:19:49 am »
thanks Leledumbo!
I will try that tomorrow.
It is 2:19 AM here .

epergola

  • Full Member
  • ***
  • Posts: 129
Re: action= in html form to return response to calling browser?
« Reply #8 on: October 06, 2017, 09:32:43 pm »
No, that did not work. It works fine on my PC but when I put the IP of the router in a remote PC (ex. 187.35.1.34:81/dothis) it gets to submit the login form but when it submits that the remote PC gets no response. There is something in the welcomepage.html (I had attached) that I do wrong

epergola

  • Full Member
  • ***
  • Posts: 129
Re: action= in html form to return response to calling browser?
« Reply #9 on: October 06, 2017, 11:25:39 pm »
I found the solution
<form method="POST" action="#">
works with html5.

Leledumbo

  • Hero Member
  • *****
  • Posts: 7743
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: action= in html form to return response to calling browser?
« Reply #10 on: October 07, 2017, 07:38:46 am »
I found the solution
<form method="POST" action="#">
works with html5.
I don't know what your server side is doing, but essentially the browser just sends back that action plainly as REQUEST_URI header to the HOST header in previous response, i.e. "/", "#" and even "" will be sent without any modifications. It's kinda weird, but OK if that solves the problem.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus