zoukankan      html  css  js  c++  java
  • java通过http调用服务

    package test;
    
    import java.io.IOException;
    
    import org.apache.commons.httpclient.Cookie;
    import org.apache.commons.httpclient.HttpClient;
    import org.apache.commons.httpclient.HttpException;
    import org.apache.commons.httpclient.methods.GetMethod;
    
    public class TestHttpclient {
    
        public static void main(String[] args) throws HttpException, IOException {
            // TODO Auto-generated method stub
            HttpClient httpclient=new HttpClient();//创建一个客户端,类似打开一个浏览器  
            GetMethod getMethod=new GetMethod("http://www.baidu.com");//创建一个get方法,类似在浏览器地址栏中输入一个地址  
            int statusCode=httpclient.executeMethod(getMethod);//回车——出拳!  
            System.out.println("response=" + getMethod.getResponseBodyAsString());//察看拳头命中情况,可以获得的东西还有很多,比如head, cookies等等  
            getMethod.releaseConnection();//释放,记得收拳哦 
            
    //        Cookie[] cookies = httpclient.getState().getCookies();  
    //        System.out.println("Present cookies: ");  
    //        for (int i = 0; i < cookies.length; i++) {//循环结构零部件  
    //            System.out.println(" - " + cookies[i].toExternalForm());  
    //            System.out.println(" - domain=" + cookies[i].getDomain());  
    //            System.out.println(" - path=" + cookies[i].getPath());  
    //                       
    //        }  
            
        }
    
    }
  • 相关阅读:
    DBCP连接池
    获取自动生成的主键
    将图片存储到数据库中
    java.nio.file.AccessDeniedException
    mysql8 :客户端连接caching-sha2-password问题
    理解 Android Build 系统(转载)
    C build error fix
    linux硬链接和软链接的区别
    du -sh
    linux proc maps文件分析
  • 原文地址:https://www.cnblogs.com/huhuuu/p/4651230.html
Copyright © 2011-2022 走看看