zoukankan      html  css  js  c++  java
  • 创建http对象

    package test;

    import java.net.HttpURLConnection;
    import java.net.URL;

    import javax.servlet.http.HttpServlet;

    public class MainTest extends HttpServlet{

      private static final long serialVersionUID = 1L;

      public static void main(String[] args) {
        //HttpServletRequest request = ServletActionContext.getRequest();
        String locationUrl = "http://www.baidu.com";
        URL url;
        try {
          url = new URL(locationUrl);
          HttpURLConnection connection;
          connection = (HttpURLConnection) url.openConnection();
          connection.setDoInput(true);
          //超时设置
          connection.setReadTimeout(10000);
          connection.setRequestMethod("POST");
          connection.setRequestProperty("Content-Type", "text/html");
          connection.setRequestProperty("Accept-Charset", "utf-8");
          connection.setRequestProperty("contentType", "utf-8");
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }

  • 相关阅读:
    20150316--TP-01
    20150314--TP-02
    20150314--TP-01
    20150313+微信-全
    表单/iframe与video标签
    图像/超链接标签
    HTML列表与表格
    JAVA新的一天
    MySQL常用函数
    php基础--来自网页转载
  • 原文地址:https://www.cnblogs.com/hxinbk/p/6777637.html
Copyright © 2011-2022 走看看