zoukankan      html  css  js  c++  java
  • 如何使用JAVA请求HTTP

    package com.st.test;
    
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.UnsupportedEncodingException;
    import java.net.HttpURLConnection;
    import java.net.URL;
    
    import com.st.util.DesEcbUtil;
    
    /**
     * @description 
     *
     * @author wangkang
     *
     * @date 2017-5-18 下午3:02:20
     *
     * @version 1.0
     */
    public class TestHttps {
    
        /**
         * @description 
         *
         * @author wangkang
         * @throws IOException 
         * @throws UnsupportedEncodingException 
         *
         * @date 2017-5-18 下午3:02:20
         */
        public static void main(String[] args) throws UnsupportedEncodingException, IOException {
            
         String testUrl
    = "http://*"; URL url = new URL(testUrl); HttpURLConnection conn = (HttpURLConnection)url.openConnection(); conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.getOutputStream().write("请求内容".getBytes("GBK")); InputStream inStream=conn.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(inStream,"UTF-8")); String line = null; StringBuffer buffer = new StringBuffer(); while((line = reader.readLine()) != null){ buffer.append(line); } System.out.println("结果:"+buffer.toString()); conn.disconnect(); } }
  • 相关阅读:
    我的SICP习题解答-chapter 1
    redis主从复制实验,使用ruby
    python连接redis
    ruby连接redis
    python中的classmethod和staticmethod有什么不同[转载]
    安装配置rails环境
    试用memcached高可用repcached
    试用memcached
    Python一个很好玩的特性decorator
    mybatis随笔四之MapperProxy
  • 原文地址:https://www.cnblogs.com/wangkang0320/p/6874725.html
Copyright © 2011-2022 走看看