zoukankan      html  css  js  c++  java
  • Apache HttpComponents POST提交带参数提交

    public class Test {
    
        public static void main(String[] args) throws IOException {
            
            DefaultHttpClient httpclient = new DefaultHttpClient();
            try {
    
                HttpPost httpost = new HttpPost("http://localhost:8080/task/index.jsp");
    
                List <NameValuePair> nvps = new ArrayList <NameValuePair>();
                nvps.add(new BasicNameValuePair("IDToken1", "username"));
                nvps.add(new BasicNameValuePair("IDToken2", "password"));
    
                httpost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));
                
                HttpResponse response = httpclient.execute(httpost);
                HttpEntity entity = response.getEntity();
    
                System.out.println("Login form get: " + response.getStatusLine());
                EntityUtils.consume(entity);
    
                System.out.println("Post logon cookies:");
                List<Cookie> cookies = httpclient.getCookieStore().getCookies();
                if (cookies.isEmpty()) {
                    System.out.println("None");
                } else {
                    for (int i = 0; i < cookies.size(); i++) {
                        System.out.println("- " + cookies.get(i).toString());
                    }
                }
            } finally {
                httpclient.getConnectionManager().shutdown();
            }
        }
    
    }
  • 相关阅读:
    MySQL管理
    MySQL触发器
    板块龙头与行业龙头
    货币宽松结束
    调整
    职业操盘手不传之秘:识别平台突破的技巧原则详解---赶牛寻渔
    chan
    2017板块轮动参考
    各种建筑风格及其代表建筑
    3分钟看懂各种建筑结构优劣
  • 原文地址:https://www.cnblogs.com/daxin/p/3165156.html
Copyright © 2011-2022 走看看