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(); } }
  • 相关阅读:
    2016年第9本:系统之美
    2016年第8本:不可思议的心理控制实验
    2016年第7本:非暴力沟通
    用SDWebImage渐变加载图片
    iOS相册、相机、通讯录权限获取
    屏蔽iOS10模拟器海量的垃圾debug信息
    Swift
    Swift
    PlaceholderImageView
    Swift
  • 原文地址:https://www.cnblogs.com/wangkang0320/p/6874725.html
Copyright © 2011-2022 走看看