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();
            }
        }
    
    }
  • 相关阅读:
    JSP
    Cookie
    HTTP
    Android布局属性详解剖析
    布局填充器的三种写法
    Linux笔记
    修改设置中数据流量小部件开关跟设置中流量开关同步
    adb 获取手机值
    java 中读取本地文件中字符
    android动画效果编程基础--Android Animation
  • 原文地址:https://www.cnblogs.com/daxin/p/3165156.html
Copyright © 2011-2022 走看看