简体   繁体   English

重定向到AND将数据发布到外部页面

[英]Redirecting to AND posting data to an external page

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. 我在.NET 3.5 Web窗体站点上有一个搜索页面,该页面根据用户的搜索参数将用户重定向到外部站点。 I would redirect to: http://www.site.com/search.aspx?searchterm=Hello . 我将重定向到: 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. 但是现在他们正在更改站点,以便将搜索参数作为POST参数而不是在查询字符串中传递。 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? 这是我可以在Web Forms中完成的一些工作,而无需采取一些应急措施? Or maybe it can be done using jQuery? 还是可以使用jQuery完成?

Most browsers will explicitely deny this. 大多数浏览器会明确否认这一点。 Doing a cross server post like this would lead to security issues. 像这样跨服务器发布将导致安全问题。

You can create simple JavaScript function for execute POST redirect to external page (dynamicaly generate and initilaze form object and submit it). 您可以创建简单的JavaScript函数来执行POST重定向到外部页面(动态生成并初始化表单对象并提交)。 For example (values pattern: a=1&b=2&c=3 ...): 例如(值模式: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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM