Cross-domain requests, as the name implies, are resources in one site to access resources on another different domain name site. A resource can be a request, or an operation or a data flow, etc.
For security reasons, if you want to request the content of another website www.b.com from www.a.com through Ajax, the browser will not allow you to do so (do not understand what security means here?). Think about what hackers can do without this limitation. What kind of situation is cross-domain? Domain name is different that of course is cross-domain, for example, a.com to b.com send a request, which is of course cross-domain, not allowed. However, different subdomains (such as sub.a.com sending requests to www.a.com) or even different ports (such as a.com:80 to a.com:8080) are also cross-domain.
[Reprint]java to access the cross-domain site, return the corresponding data
(2012-12-20 18:45:28)
Reproduced
Label: Reproduced |
Category: Programming |
Original address:Java access to cross-domain site, return the corresponding data in the effort of the baby
Package com.zssoft.test;
Import java.io.*;
Import Java.net.URL;
Import java.net.URLConnection;
public class Test11 {
public static void Main (string[] args) throws IOException {
Test4 ();
Test3 ();
Test2 ();
Test ();
}
public static void Test4 () throws IOException {
URL url = new URL ("Http://lavasoft.blog.51cto.com/attachment/200811/200811271227767778082.jpg");
Get the contents of this URL.
Object obj = url.getcontent ();
System.out.println (Obj.getclass (). GetName ());
}
public static void Test3 () throws IOException {
URL url = new URL ("http://www.baidu.com");
Returns a URLConnection object that represents the connection to the remote object referenced by the URL.
URLConnection UC = Url.openconnection ();
An open connection reads the input stream.
InputStream in = Uc.getinputstream ();
int C;
while ((c = In.read ())! =-1)
System.out.print (c);
In.close ();
}
public static void Test2 () throws IOException {
URL url = new URL ("http://www.baidu.com");
Opens a connection to this URL and returns a InputStream that is used to read from the connection.
Reader reader = new InputStreamReader (New Bufferedinputstream (Url.openstream ()));
int C;
while ((c = Reader.read ())! =-1) {
System.out.print ((char) c);
}
Reader.close ();
}
public static void Test () throws IOException {
URL url = new URL ("http://lavasoft.blog.51cto.com/62575/120430");
Opens a connection to this URL and returns a InputStream that is used to read from the connection.
InputStream in = Url.openstream ();
int C;
while ((c = In.read ())! =-1)
System.out.print (c);
In.close ();
}
}
Java cross-domain