开发者

CROSS-DOMAIN - Retrieve Page Source

开发者 https://www.devze.com 2023-04-09 19:13 出处:网络
Hi I have a project here at work where we need a specific value from another domain I do not have access to change (So I can\'t do nested iframes, or CORS).We need to keep Session/Cookie state the sam

Hi I have a project here at work where we need a specific value from another domain I do not have access to change (So I can't do nested iframes, or CORS). We need to keep Session/Cookie state the same to get the required 开发者_JAVA技巧data from the page as the token changes based on the user on the page. So a server side solution wouldn't work.

What is the best way to go about this, the following is what the page source is in it's entirety. I need to retrieve the FF321332 value

{"<!--":"","token":"FF321332","expire":1317448445,"":"--><body onload=document.body.innerHTML=clear>"}

Some things I've tried so far are Dynamic Script Tags "It throws a JS error Unexpected token : error, Jquery (.getScript ) this throws the same error, any other form of .get or xhr will throw a Cross Domain Error.

I feel like I was on the right track with the .getScript or Dynamic Script Tags as it almost wants to read it in. But if I can get around the Unexpected token error and just read it in as text (if this is possible) I can just parse out the variable as normal text.

Any assistance in this would be greatly appreciated.


JSONP allows you to do what you are trying to do. Check out the jQuery doc on how to make your .get use JSONP to side step the browser cross-domain enforcement.

Essentially, when you do $.getJSON, if the url has a piece that says "callback=" + whatever, then it will treat it as jsonp instead of the standard getjson.

Good luck.


Don't think you can get past the error using script tags, because normally, once the "javascript" specified in the src attribute gets downloaded it also gets executed. You said you can't use a server side solution because you need to preserve state?

Well you can do that using curl and a cookie jar. Never tried this before but in theory it should work: Basically all you need to do is setup a curl request to the remote domain to accept cookies and store those in a file (cookie jar) and then do a second request to fetch the page passing along the previous obtained cookies.

Give it a try, maybe it will work.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号