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();
            }
        }
    
    }
  • 相关阅读:
    kubenetes-学习
    k8s-字段
    Spring Boot集成mongodb
    synchronized关键字
    Scala手记
    Python数据结构&封装解构
    Scala基础之集合
    Scala基础之集合常用方法
    Scala(2.12)之collection基本操作
    Scala基础之集合(数组)
  • 原文地址:https://www.cnblogs.com/daxin/p/3165156.html
Copyright © 2011-2022 走看看