0

I have a search page on my .NET 3.5 Web Forms site that redirects a user to an external site based on the user's search parameters. I would redirect to: http://www.site.com/search.aspx?searchterm=Hello.

But now they are changing the site so that the search parameter is passed as a POST parameter, and not in the query string. So the page is expecting "searchterm".

So not only do I need to redirect to the external page, I have to post data to the page as well. I have no idea how to do this and I don't know where to start.

Is this something I can do in Web Forms without some glitchy workaround? Or maybe it can be done using jQuery?

Steven
  • 18,761
  • 70
  • 194
  • 296
  • possible duplicate of [Response.Redirect with POST instead of Get?](http://stackoverflow.com/questions/46582/response-redirect-with-post-instead-of-get) – Jeff Sternal Sep 27 '10 at 17:35

2 Answers2

1

Most browsers will explicitely deny this. Doing a cross server post like this would lead to security issues.

Mike
  • 3,462
  • 22
  • 25
  • Well how about if it's on the same server? – Steven Sep 27 '10 at 17:37
  • You would still need to do this from the client side. Just change the form action to point to the desired URL instead of doing the server side redirect. – Mike Sep 27 '10 at 17:51
0

You can create simple JavaScript function for execute POST redirect to external page (dynamicaly generate and initilaze form object and submit it). For example (values pattern: a=1&b=2&c=3 ...):

function bind(pageURL, values) {
var form=document.createElement('form');
form.action= pageURL;
form.target='_blank';
form.style.display = 'none';
form.method = 'POST';

var valuesSplit = node.get_value().toString().split("&");

    for (var i = 0; i < valuesSplit.length - 1; i++) {
        var p = valuesSplit[i];
        var ps = p.split('=');
        addParam(form, ps[0], ps[1]);
    }

document.body.appendChild(form);
form.submit();
}

function addParam(form,key,value){
  var input= document.createElement('input');
  input.name=key;
  input.value=value;
  form.appendChild(input);
}
ASergan
  • 171
  • 8