import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; /** * Created by Administrator on 2017/6/6. */ public class RefererTest { public static void main(String[] args) throws Exception { String url = "http://lb.gfstack.geo:8080/OperationProxy/GatewayProxy/text06061532/Text?version=1.0.0&service=TEXT&f=json"; HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon;)"); conn.setRequestProperty("referer", "http://www.abc1.com"); InputStream is = conn.getInputStream(); StringBuffer sb = new StringBuffer(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String strLine = ""; while ((strLine = br.readLine()) != null) { sb.append(strLine.trim()); } System.out.println(sb.toString()); } }