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(); } }
  • 相关阅读:
    初识Ubuntu 18.04(更换系统头像,截图,sy)
    HDU
    HDU
    进度1
    开课博客
    返回一个整数数组中最大子数组的和
    开学第一节课测试感受
    网页记账本开发四(基本完成)
    网页记账本开发三
    网页记账本开发二
  • 原文地址:https://www.cnblogs.com/wangkang0320/p/6874725.html
Copyright © 2011-2022 走看看