首页 > Web开发 > 详细

创建http对象

时间:2017-04-27 22:36:40      阅读:172      评论:0      收藏:0      [点我收藏+]

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();
    }
  }
}

创建http对象

原文:http://www.cnblogs.com/hxinbk/p/6777637.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!