码迷,mamicode.com
首页 > Web开发 > 详细

创建http对象

时间:2017-04-27 23:09:37      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:imp   cat   设置   pac   inpu   charset   eth   ext.get   final   

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对象

标签:imp   cat   设置   pac   inpu   charset   eth   ext.get   final   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!