473,545 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to simulate post method while redirecting to new URL?

3 New Member
Hi Coders,
I have to redirect from my server to the different server page by simulating the POST method submit from the Controller file, I tried using post_via_redire ct, but could not succeed... though redirect_to just redirects to given URL, I need to pass parameters using POST.
Configurations:
Rails 1.2.3,
ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-linux]
Linux 2.6.9-42 box.

I used the following code in the action method:
post_via_redire ct("http://some_site:8080/login.xhtml",{: userName => 'login_id', :password => 'some_password' })
which failed to redirect and asking for the file template with the action name.

if I use redirect_to ("http://some_site:8080/login.xhtml") it will take me to login page, which I dont want, I should directly login without entering username and password.

If I call this page using HTML form Submit (POST method with username and password) it directly logs into the system.
Ex:
Expand|Select|Wrap|Line Numbers
  1.   <form method=post action="http://some_site:8080/login.xhtml">
  2.   <input type="hidden" id="userName" name="userName" value="login_id" >
  3.   <br>
  4.   <input type="hidden" id="password" name="password" value="some_password" > 
  5.   <br>
  6.   <input type="submit" value="submit">
  7.  
Scenario explained in detail :
I have to click on the button in my home page, which calls a Controler/action
in that action, I need to redirect to new url (ex: http://new_site:8080/login)
while redirecting, I need to post the username and password as a POST arguments and NOT in the URL (get method).

If there are any Sample code, it will be very helpful.

Thanks,
Chandu
Sep 12 '08 #1
6 29729
improvcornartist
303 Recognized Expert Contributor
I've never tried to do that before, so my only thought is to try
Expand|Select|Wrap|Line Numbers
  1. redirect_to("http://some_site:8080/login.xhtml?userName=login_id&password=some_password)
Sep 12 '08 #2
rpcchandu
3 New Member
I've never tried to do that before, so my only thought is to try
Expand|Select|Wrap|Line Numbers
  1. redirect_to("http://some_site:8080/login.xhtml?userName=login_id&password=some_password)
Thanks for replying, but as you can see, sending username and password is security prone, and which is not the desired solution, we need to hide the username and password from displaying it in the firebug and sort of it(which displays the entire GET parameters in the URL).

And the other server code (which is maintained by others) works only for POST method, and GET method from URL is not handled.

If you have any other solution, that would be a great helpful.
Sep 15 '08 #3
rpcchandu
3 New Member
I got a round about solution for that, I created a rhtml page in the name of action, and added the FORM with method=post, and generated the html, at the end of the form, I used the script to submit the form, this works very quick (though I have added a Loading... icon in the div to avoid seeing the blank page just in case).

File: app/controllers/my_redirect_con troler.rb
Expand|Select|Wrap|Line Numbers
  1. ...
  2. def redirect_post
  3. end
  4. ...
  5.  
Inside app/views/my_redirect/redirect_post.r html
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <form method=post action="http://some_site:8080/login.xhtml" id='my_form'>
  4. <input type="hidden" id="userName" name="userName" value="login_id" >
  5. <input type="hidden" id="password" name="password" value="some_password" >
  6. </form>
  7.   <script>
  8.     document.getElementById("my_form").submit()
  9.   </script>
  10.  </body>
  11. </html>
  12.  
So, now from the index page if I have a link which links to the action->controller
Expand|Select|Wrap|Line Numbers
  1. <%= link_to( image_tag("Redirect.gif"), {:controller=>'my_redirect', :action => "redirect_post"})%>
  2.  
This will solve me the problem I was facing.

Cheers..
Sep 17 '08 #4
improvcornartist
303 Recognized Expert Contributor
That sounds like that should work. Alternatively, could you put the form on the index page, so when you click the link, it submits the form instead of redirecting? That might save you the redirect page and you wouldn't have to use javascript.
Sep 17 '08 #5
niklas
1 New Member
I think that this is still a security hole, big enough to build a highway through...
You are still sending the username & password to the user's computer and posting it from there then.
If the user doesn't have JS activated, the form will never be posted, so she will be able to look in the source and see the response there. (or with JS enabled even more easier, simply click on the request in firebug and see the post values there). By the way: the same is true for search engines...
Oct 8 '08 #6
MMcCarthy
14,534 Recognized Expert Moderator MVP
This thread is closed to posting due to repeated spamming.
Oct 7 '10 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3549
by: mickbw | last post by:
I am unable to display PHP pages generated by a submission of a form using a POST method. To illustrate this, I created a very simple form called TestForm.php . <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head>...
15
3108
by: Thomas Scheiderich | last post by:
I am trying to understand Session variables and ran into a question on how they work with data that is passed. I have an HTM file that calls an ASP file and sends the name either by GET or POST. When I find is that if I send the value by the GET method, response.write("From QueryString: " & Request.QueryString("usernamefromform") &...
2
1908
by: Asp Help | last post by:
I'm working on a ASP applicatition to create Windows 2000 users. Because I don't want everybody to have access to the site I've changed te security in IIS 5.0 which runs on a windows 2000 Sp4 server: The security on the site is mainly anonymous. The anonymous account has been changed to an account which has the right permissions. The...
7
29763
by: Eric | last post by:
I am certain the answer will be 'NO', but I wanted to ask anyway just incase I have missed something. Everyone knows that one pass data to a page in an anchor tag by using the GET Method: <a href="http://www.aaa.com/randompage.php?name=data"> What I am wondering is if there was a way to do the same thing, but use the POST Method...
4
2939
by: VB Programmer | last post by:
Can someone provide a simple explanation on the difference between the GET and POST methods? What are the adv/disadv of both and when should I use them? Thanks.
9
2111
by: WJ | last post by:
I have an Asp.Net page that redirects the user to another page with a piece of data to be passed. Below is the c# instruction: Response.Redirect("mySpecialPage.aspx?go1="+strGoName); This will expose the "go1" parameter on the Address field of the MS/IE browser because it uses the "GET" method. Is there a way that I can force the system...
5
3014
by: Vishal | last post by:
Hello, I already asked this question in the ASP.NET forums, but no help came. So I am hoping that somebody can help me out. This is really very URGENT me. For my e-commerce application, I need to send data from my server via the post method to the payment server. The payment server does not run asp.net. I dont know what they run. The...
0
1205
by: Ricardo Magalhaes | last post by:
Hi, I have an ASPX page and I need to call an ASP page sending parameters like Name, Adress, ie. using POST method. This next ASP page show payment informations.. If was from an ASP to another ASP page I'll write the code: <form action=boleto.asp method=post> <input type=text name="adress" value="adress abc">
5
1857
by: Bob Bedford | last post by:
Hi all, I've to accept a file that is sent using a POST method. The file will be sent using this URL: http://username:pass@www.mysite.com/upload.php How can I retrieve the username and passord and rename the file ? Should I use substring using the URI ? Pseudocode below is the best way to do so ?
0
7475
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7664
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7921
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7771
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
4958
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1900
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1023
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
720
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.