首页 > 代码库 > java 发起 HTTP请求
java 发起 HTTP请求
import java.net.HttpURLConnection;import java.net.URL;import java.io.IOException;import java.io.InputStream;import java.io.BufferedReader;import java.io.InputStreamReader;public class httpGet{ private URL url; private HttpURLConnection httpURLConn; public void myDoGet() { try { String temp = new String(); url = new URL("http://localhost:8080/myServlet/welcome"); httpURLConn= (HttpURLConnection)url.openConnection(); httpURLConn.setDoOutput(true); httpURLConn.setRequestMethod("GET"); httpURLConn.setIfModifiedSince(999999999); httpURLConn.setRequestProperty("Referer", "http://localhost:80"); httpURLConn.setRequestProperty("User-Agent", "test"); httpURLConn.connect(); InputStream in =httpURLConn.getInputStream(); BufferedReader bd = new BufferedReader(new InputStreamReader(in)); while((temp=bd.readLine())!=null) { System.out.println(temp); } } catch (Exception e) { e.printStackTrace(); } finally { if(httpURLConn!=null) { httpURLConn.disconnect(); } } } public static void main(String[] args) { httpGet hg = new httpGet(); hg.myDoGet(); }}
java 发起 HTTP请求
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。