HttpURLConnection 是JDK内置一类;位于java.net包下面!也就说明在使用可以直接使用!
SOA 面向服务架构 对应SOA 应该有大概的了解的就知道 HttpRULConnection这个类就和这个SOA思想差不多。
说白了就是两个不同的程序进行数据交互;现在对这个类有了大概地的想法了吧!哈哈,就是这样的。。。不知道是不是这个意思,个人就是这么认为!欢迎大家指正!
详细用法参考JKD API 下面提供一个简单的例子:
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
public class HttpUrlconnectionDemo {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// New Request URL
URL url = new URL("http://lenovo:8080/CM/logon.do");
//Open connection
URLConnection urlconnection = url.openConnection();
HttpURLConnection httpurlconnection = (HttpURLConnection) urlconnection;
//Set HttpURLConnection ags...
httpurlconnection.setDoOutput(true);
httpurlconnection.setDoInput(true);
httpurlconnection.setUseCaches(false);
httpurlconnection.setRequestProperty("Content-type", "application/x-java-serialized-object");
httpurlconnection.setRequestMethod("POST");
// bulid TCP connect Only Connect !!! ;
httpurlconnection.connect();
//init Send data
OutputStream op = httpurlconnection.getOutputStream();
ObjectOutputStream objoutstrm = new ObjectOutputStream(op);
objoutstrm.writeObject(new Student("lxd",24));
objoutstrm.flush();
objoutstrm.close();
// Send data
InputStream ip = httpurlconnection.getInputStream();
ip.close();
}
}