Here you can find the source of sendGetRequest(String url, String cookies)
public static String sendGetRequest(String url, String cookies) throws MalformedURLException, IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; public class Main { public static String sendGetRequest(String url, String cookies) throws MalformedURLException, IOException { HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); conn.setRequestProperty("Cookie", cookies); conn.setRequestProperty("Referer", "http://login.sina.com.cn/signup/signin.php?entry=sso"); conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:34.0) Gecko/20100101 Firefox/34.0"); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); BufferedReader read = new BufferedReader(new InputStreamReader(conn.getInputStream(), "gbk")); String line = null;/*w w w .j a va 2s . c o m*/ StringBuilder ret = new StringBuilder(); while ((line = read.readLine()) != null) { ret.append(line).append("\n"); } StringBuilder ck = new StringBuilder(); try { for (String s : conn.getHeaderFields().get("Set-Cookie")) { ck.append(s.split(";")[0]).append(";"); } } catch (Exception e) { } return ck.toString(); } }