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(); } }
  • 相关阅读:
    各种小知识
    基础技能
    st表
    有理数取余
    FFT加速高精度乘法
    unique
    离散化
    线段树复杂度分析
    楼房重建
    电脑装系统常用方法
  • 原文地址:https://www.cnblogs.com/wangkang0320/p/6874725.html
Copyright © 2011-2022 走看看