Summary of js cross-origin and ajax cross-origin problems

Source: Internet
Author: User

If Javascript is to be cross-origin, you can use:
<Script src = "js addresses of other websites (the inner space can be dynamically generated, such as aaa. jsp and bbb. aspx. "> </Script> you can read data from other websites.
The key is to see if your spirit is not flexible and you will use it.
To cross-origin ajax, you can use the server to retrieve content from other websites, such as asp.net: Copy codeThe Code is as follows: public string GetUrlData (string url)
{
System. Net. HttpWebRequest webRequest = (System. Net. HttpWebRequest) System. Net. WebRequest. Create (url );
System. Net. WebResponse webResponse = webRequest. GetResponse ();
System. IO. Stream iStream = webResponse. GetResponseStream ();
System. IO. StreamReader sr = new System. IO. StreamReader (iStream, System. Text. Encoding. Default );
String str = sr. ReadToEnd ();
Sr. Close ();
IStream. Close ();
WebResponse. Close ();
Return str;
}

This method has been written. You only need to input the url of the website to obtain the ajax return value.
In this way, the ajax requests of other websites are written to your own server, and then you can use ajax to request the one you wrote.
The aspx address is enough.
The same applies to java, for example:Copy codeThe Code is as follows: URL url = new URL ("http://www.jb51.net ");
FilterInputStream f = (FilterInputStream) url. openStream ();

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.