首页 文章

使用JavaScript将POST值传递到中间页面

提问于
浏览
0

我有一种情况,我对如何完成有点困惑 .

Example domains: http://url1.com http://url2.com

url1.com有一个注册表单url2.com有另一种形式 .

我需要将POST值从url1.com传递到url2.com而不会发生实际提交 . 在url2.com上,我需要使用来自url1.com的POST值重建表单,并将隐藏的输入值附加到重建的表单,然后提交 . 如果可能的话,我想用JavaScript / jQuery完成这个 .

我想请注意,url1.com包含一个带登录名和密码的注册表 .

任何意见是极大的赞赏 .

提前致谢 .

1 回答

  • 1

    以下是您可以发布到其他网址的方式:

    function post_to_url(path, params, method) {
        method = method || "post"; // Set method to post by default, if not specified.
    
        // The rest of this code assumes you are not using a library.
        // It can be made less wordy if you use one.
        var form = document.createElement("form");
        form.setAttribute("method", method);
        form.setAttribute("action", path);
    
        for(var key in params) {
            var hiddenField = document.createElement("input");
            hiddenField.setAttribute("type", "hidden");
            hiddenField.setAttribute("name", key);
            hiddenField.setAttribute("value", params[key]);
    
            form.appendChild(hiddenField);
        }
    
        document.body.appendChild(form);
        form.submit();
    }
    

    从这里复制:JavaScript post request like a form submit

    那里还有其他解决方案 .

    附:关于安全问题,请阅读:Are https URLs encrypted?

    从本质上讲,您通过安全连接传递的所有数据都是加密的,无论是GET还是POST . 请注意,即使您通过常规http发布数据,即使URL中的用户看不到,也可能被中间的人拦截 .

相关问题