62,634
社区成员




public String getURLContent(String urlStr, String encode) throws Exception{
if(isProxyEnabled){
Properties prop = System.getProperties();
prop.setProperty("http.proxyHost", proxyHost);
prop.setProperty("http.proxyPort", proxyPort);
}
URL url = new URL(urlStr);
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
httpConn.setUseCaches(false);
httpConn.setRequestMethod("POST");
httpConn.setInstanceFollowRedirects(true);
httpConn.connect();
httpConn.setConnectTimeout(3000);
httpConn.setReadTimeout(3000);
DataOutputStream out = new DataOutputStream(httpConn.getOutputStream());
out.flush();
out.close();
//OutputStream outStrm = httpConn.getOutputStream();
BufferedReader bufReader;
StringBuilder contentBuf = new StringBuilder(1024*100);
try{
bufReader = new BufferedReader(new InputStreamReader(httpConn.getInputStream(), encode));
String line = "";
while ((line = bufReader.readLine()) != null) {
contentBuf.append(line);
}
bufReader.close();
}
catch(Exception e){
e.printStackTrace();
}
httpConn.disconnect();
return new String(contentBuf);
}