处理'Content-Type': 'text/javascript'

今天在调试微信相关的接口是 我看到有个接口的'Content-Type' 为 'text/javascript' 

返回值为

window.code=200;window.redirect_uri="https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage?ticketLD5bdhhrGFLwtGqF1@qrticket_0&uuid=4emu1sc6Qg==&lang=zh_CN&scan=1558169698";

当'Content-Type' 为 'text/javascript'  实际返回的值是一个字符串.

这个时候要想处理里面的值 就比较麻烦

这个时候 可以使用 eval()    函数

具体操作如下

let confirmRes = 'window.code=200;window.redirect_uri="https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage?ticketLD5bdhhrGFLwtGqF1@qrticket_0&uuid=4emu1sc6Qg==&lang=zh_CN&scan=1558169698";'
let window = {}
eval(confirmRes)    
if (window['code'] == 200) {
   console.log(window['redirect_uri'])
   return data
}

 

如此 就能得到字符串中的变量了 非常简单.方便  

但同时这个函数是个魔鬼 

别人可以利用eval() 函数的功效 进行代码注入

拿我格子衫来 CSDN认证博客专家 拿我格子衫来 范马勇次郎 琦玉君
积土成山,风雨兴焉;积水成渊,蛟龙生焉;积善成德,而神明自得,圣心备焉。故不积跬步,无以至千里;不积小流,无以成江海。骐骥一跃,不能十步;驽马十驾,功在不舍。锲而舍之,朽木不折;锲而不舍,金石可镂。蚓无爪牙之利,筋骨之强,上食埃土,下饮黄泉,用心一也。蟹六跪而二螯,非蛇鳝之穴无可寄托者,用心躁也。
已标记关键词 清除标记
十月 06, 2016 8:42:18 下午 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify 警告: Obsolete content type encountered: 'text/javascript'. 十月 06, 2016 8:42:18 下午 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify 警告: Obsolete content type encountered: 'text/javascript'. 十月 06, 2016 8:42:18 下午 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify 警告: Obsolete content type encountered: 'text/javascript'. 十月 06, 2016 8:42:18 下午 com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController processSynchron 信息: Re-synchronized call to http://172.16.51.37/notice_listJSON.html 十月 06, 2016 8:42:18 下午 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify 警告: Obsolete content type encountered: 'text/javascript'. 十月 06, 2016 8:42:19 下午 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify 警告: Obsolete content type encountered: 'text/javascript'. 十月 06, 2016 8:42:19 下午 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify 警告: Obsolete content type encountered: 'text/javascript'. 十月 06, 2016 8:42:19 下午 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify 警告: Obsolete content type encountered: 'text/javascript'. 十月 06, 2016 8:42:19 下午 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify 警告: Obsolete content type encountered: 'text/javascript'. 十月 06, 2016 8:42:19 下午 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify 警告: Obsolete content type encountered: 'text/javascript'. 十月 06, 2016 8:42:19 下午 com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter error 严重: error: message=[missing { before function body] sourceName=[script in http://172.16.51.37/home_welcome.html from (85, 36) to (106, 10)] line=[87] lineSource=[ function initArray()...{ ] lineOffset=[26] 十月 06, 2016 8:42:19 下午 com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine handleJavaScriptException 信息: Caught script exception ======= EXCEPTION START ======== Exception class=[net.sourceforge.htmlunit.corejs.javascript.EvaluatorException] com.gargoylesoftware.htmlunit.ScriptException: missing { before function body (script in http://172.16.51.37/home_welcome.html from (85, 36) to (106, 10)#87) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:921) at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:628) at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:515) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:746) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:711) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:763) at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:904) at com.gargoylesoftware.htmlunit.html.HtmlScript.executeInlineScriptIfNeeded(HtmlScript.java:307) at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:368) at com.gargoylesoftware.htmlunit.html.HtmlScript$2.execute(HtmlScript.java:238) at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:257) at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:772) at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source) at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:729) at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1209) at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1111) at net.sourceforge.htmlunit.cyberneko.filters.DefaultFilter.endElement(DefaultFilter.java:207) at net.sourceforge.htmlunit.cyberneko.filters.NamespaceBinder.endElement(NamespaceBinder.java:337) at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:3137) at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2100) at net.sourceforge.htmlunit.cyberneko.HTMLScanner.scanDocument(HTMLScanner.java:927) at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:506) at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:459) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:979) at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:241) at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:187) at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:269) at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:157) at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:512) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:386) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:304) at com.gargoylesoftware.htmlunit.html.BaseFrameElement.loadInnerPageIfPossible(BaseFrameElement.java:184) at com.gargoylesoftware.htmlunit.html.BaseFrameElement.loadInnerPage(BaseFrameElement.java:122) at com.gargoylesoftware.htmlunit.html.HtmlPage.loadFrames(HtmlPage.java:1818) at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:226) at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:519) at com.gargoylesoftware.htmlunit.WebClient.loadDownloadedResponses(WebClient.java:2147) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.doProcessPostponedActions(JavaScriptEngine.java:946) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.processPostponedActions(JavaScriptEngine.java:1033) at com.gargoylesoftware.htmlunit.html.DomElement.click(DomElement.java:806) at com.gargoylesoftware.htmlunit.html.DomElement.click(DomElement.java:749) at com.gargoylesoftware.htmlunit.html.DomElement.click(DomElement.java:696) at TestC.main(TestC.java:45)
用WebClient模拟新浪微博登陆,有js加载问题: 异常如下: 2016-03-10 18:06:19,311 [main] WARN [com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl] - Obsolete content type encountered: 'application/x-javascript'. 2016-03-10 18:06:21,025 [JS executor for com.gargoylesoftware.htmlunit.WebClient@145a27f] WARN [com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl] - Obsolete content type encountered: 'application/x-javascript'. 2016-03-10 18:06:21,059 [JS executor for com.gargoylesoftware.htmlunit.WebClient@145a27f] WARN [com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl] - Obsolete content type encountered: 'application/x-javascript'. 2016-03-10 18:06:21,204 [main] WARN [org.apache.http.client.protocol.ResponseProcessCookies] - Cookie rejected [v="0", version:0, domain:.taobao.com, path:/, expiry:null] Illegal domain attribute "taobao.com". Domain of origin: "js1.t.sinajs.cn" 2016-03-10 18:06:21,204 [main] WARN [org.apache.http.client.protocol.ResponseProcessCookies] - Cookie rejected [cookie2="1cb93763dd883cf48427d2013efbb15b", version:0, domain:.taobao.com, path:/, expiry:null] Illegal domain attribute "taobao.com". Domain of origin: "js1.t.sinajs.cn" 2016-03-10 18:06:21,204 [main] WARN [org.apache.http.client.protocol.ResponseProcessCookies] - Cookie rejected [t="e5f50b797c4e59839d80b1961ae45398", version:0, domain:.taobao.com, path:/, expiry:Wed Jun 08 18:06:21 CST 2016] Illegal domain attribute "taobao.com". Domain of origin: "js1.t.sinajs.cn" 2016-03-10 18:06:21,205 [main] WARN [org.apache.http.client.protocol.ResponseProcessCookies] - Cookie rejected [_tb_token_="6v92BCkEPJskjf", version:0, domain:.taobao.com, path:/, expiry:null] Illegal domain attribute "taobao.com". Domain of origin: "js1.t.sinajs.cn" 2016-03-10 18:06:21,249 [main] WARN [com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl] - Obsolete content type encountered: 'application/x-javascript'. 2016-03-10 18:06:21,331 [main] WARN [com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl] - Obsolete content type encountered: 'application/x-javascript'. 2016-03-10 18:06:21,340 [main] WARN [com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl] - Obsolete content type encountered: 'application/x-javascript'. 2016-03-10 18:06:21,358 [main] WARN [com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl] - Obsolete content type encountered: 'application/x-javascript'. 2016-03-10 18:06:21,395 [main] WARN [com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl] - Obsolete content type encountered: 'application/x-javascript'. 2016-03-10 18:06:21,412 [main] WARN [com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl] - Obsolete content type encountered: 'application/x-javascript'. 2016-03-10 18:06:21,451 [JS executor for com.gargoylesoftware.htmlunit.WebClient@145a27f] WARN [com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl] - Obsolete content type encountered: 'application/x-javascript'. 2016-03-10 18:06:21,533 [main] WARN [com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl] - Obsolete content type encountered: 'application/x-javascript'. 2016-03-10 18:06:21,728 [main] WARN [com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl] - Obsolete content type encountered: 'application/x-javascript'. 2016-03-10 18:06:21,809 [main] WARN [com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl] - Obsolete content type encountered: 'text/javascript'. 2016-03-10 18:06:22,071 [JS executor for com.gargoylesoftware.htmlunit.WebClient@145a27f] WARN [com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl] - Obsolete content type encountered: 'application/x-javascript'. 2016-03-10 18:06:22,084 [JS executor for com.gargoylesoftware.htmlunit.WebClient@145a27f] WARN [com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl] - Obsolete content type encountered: 'application/x-javascript'. 2016-03-10 18:06:22,143 [main] WARN [org.apache.http.client.protocol.ResponseProcessCookies] - Cookie rejected [cna="HjVoD15v7R4CAdz4Edobp0iZ", version:0, domain:.mmstat.com, path:/, expiry:Sun Mar 08 18:06:22 CST 2026] Illegal domain attribute "mmstat.com". Domain of origin: "g.alicdn.com" 2016-03-10 18:06:22,143 [main] WARN [org.apache.http.client.protocol.ResponseProcessCookies] - Cookie rejected [sca="37e55bc2", version:0, domain:.mmstat.com, path:/, expiry:null] Illegal domain attribute "mmstat.com". Domain of origin: "g.alicdn.com" 2016-03-10 18:06:22,143 [main] WARN [org.apache.http.client.protocol.ResponseProcessCookies] - Cookie rejected [tbsa="a63b6f131cd4ff69ca5bf61d_1457604382_1", version:0, domain:.mmstat.com, path:/, expiry:null] Illegal domain attribute "mmstat.com". Domain of origin: "g.alicdn.com" 2016-03-10 18:06:22,143 [main] WARN [org.apache.http.client.protocol.ResponseProcessCookies] - Cookie rejected [atpsida="13075126e2ff6c8b00f358f8_1457604382", version:0, domain:.mmstat.com, path:/, expiry:Sun Mar 08 18:06:22 CST 2026] Illegal domain attribute "mmstat.com". Domain of origin: "g.alicdn.com" 2016-03-10 18:06:23,071 [JS executor for com.gargoylesoftware.htmlunit.WebClient@145a27f] WARN [com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl] - Obsolete content type encountered: 'application/x-javascript'. 2016-03-10 18:06:23,081 [JS executor for com.gargoylesoftware.htmlunit.WebClient@145a27f] WARN [com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl] - Obsolete content type encountered: 'application/x-javascript'. 2016-03-10 18:06:51,208 [JS executor for com.gargoylesoftware.htmlunit.WebClient@145a27f] WARN [com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl] - Obsolete content type encountered: 'application/x-javascript'. 2016-03-10 18:06:51,226 [JS executor for com.gargoylesoftware.htmlunit.WebClient@145a27f] WARN [com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl] - Obsolete content type encountered: 'application/x-javascript'. 2016-03-10 18:06:51,302 [JS executor for com.gargoylesoftware.htmlunit.WebClient@145a27f] WARN [com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl] - Expected content type of 'application/javascript' or 'application/ecmascript' for remotely loaded JavaScript element at 'http://wbpctips.mobile.sina.cn/adfront/loginadv.php?posid=pos55dc4af3e7219&psid=PDPS000000025446&cip=220.248.17.218&cursor=15&eData=32.07,1&uid=1000959614999&callback=wbad_14576528474261&rnd=14577027909572', but got 'text/html'. 2016-03-10 18:06:51,313 [JS executor for com.gargoylesoftware.htmlunit.WebClient@145a27f] WARN [com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl] - Obsolete content type encountered: 'application/x-javascript'. 2016-03-10 18:06:51,343 [JS executor for com.gargoylesoftware.htmlunit.WebClient@145a27f] WARN [com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl] - Obsolete content type encountered: 'application/x-javascript'. 2016-03-10 18:06:51,435 [JS executor for com.gargoylesoftware.htmlunit.WebClient@145a27f] WARN [com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl] - Expected content type of 'application/javascript' or 'application/ecmascript' for remotely loaded JavaScript element at 'http://login.sina.com.cn/sso/prelogin.php?entry=weibo&callback=sinaSSOController.preloginCallBack&su=&rsakt=mod&client=ssologin.js(v1.4.18)&_=1457604411336', but got 'text/html'. 2016-03-10 18:07:21,391 [JS executor for com.gargoylesoftware.htmlunit.WebClient@145a27f] WARN [com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl] - Obsolete content type encountered: 'application/x-javascript'. 2016-03-10 18:07:21,422 [JS executor for com.gargoylesoftware.htmlunit.WebClient@145a27f] WARN [com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl] - Obsolete content type encountered: 'application/x-javascript'. 2016-03-10 18:07:51,352 [JS executor for com.gargoylesoftware.htmlunit.WebClient@145a27f] INFO [com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine] - Caught script exception 模拟点击“登陆”的a标签,预计因为js没有加载所以无法提交;a标签点击过后 还是返回的登陆界面! 模拟点击代码: HtmlAnchor login_a = page.getFirstByXPath("//*[@id=\"pl_login_form\"]/div[2]/div[1]/div/a[2]"); login_a.click(); 有谁知道什么解决不?
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页