欧美日韩不卡一区二区三区,www.蜜臀.com,高清国产一区二区三区四区五区,欧美日韩三级视频,欧美性综合,精品国产91久久久久久,99a精品视频在线观看

java語言

java設(shè)置代理IP訪問網(wǎng)站的方法

時(shí)間:2025-03-17 02:42:58 java語言 我要投稿
  • 相關(guān)推薦

java設(shè)置代理IP訪問網(wǎng)站的方法

  Java 技術(shù)具有卓越的通用性、高效性、平臺(tái)移植性和安全性,廣泛應(yīng)用于PC、數(shù)據(jù)中心、游戲控制臺(tái)、科學(xué)超級(jí)計(jì)算機(jī)、移動(dòng)電話和互聯(lián)網(wǎng),同時(shí)擁有全球最大的開發(fā)者專業(yè)社群。以下是小編為大家搜索整理的java設(shè)置代理IP訪問網(wǎng)站的方法,希望能給大家?guī)韼椭?更多精彩內(nèi)容請(qǐng)及時(shí)關(guān)注我們應(yīng)屆畢業(yè)生考試網(wǎng)!

  1.源碼

  import java.io.BufferedInputStream;

  import java.net.URL;

  import java.net.URLConnection;

  public class TestProxyIp {

  public static void main(String args[]){

  //System.getProperties().setProperty("proxySet", "true"); //如果不設(shè)置,只要代理IP和代理端口正確,此項(xiàng)不設(shè)置也可以

  System.getProperties().setProperty("http.proxyHost", "218.26.204.66");

  System.getProperties().setProperty("http.proxyPort", "8080");

  System.out.println(getHtml("http://www.ip138.com/ip2city.asp")); //判斷代理是否設(shè)置成功

  }

  private static String getHtml(String address){

  StringBuffer html = new StringBuffer();

  String result = null;

  try{

  URL url = new URL(address);

  URLConnection conn = url.openConnection();

  conn.setRequestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB5; .NET CLR 2.0.50727; CIBA)");

  BufferedInputStream in = new BufferedInputStream(conn.getInputStream());

  try {

  String inputLine;

  byte[] buf = new byte[4096];

  int bytesRead = 0;

  while (bytesRead >= 0) {

  inputLine = new String(buf, 0, bytesRead, "ISO-8859-1");

【java設(shè)置代理IP訪問網(wǎng)站的方法】相關(guān)文章:

局域網(wǎng)ip設(shè)置方法11-02

java設(shè)置光標(biāo)位置方法09-19

java設(shè)置cookie方法流程09-20

Ubuntu Linux系統(tǒng)下設(shè)置Static IP的方法09-05

java環(huán)境變量的設(shè)置方法09-14

實(shí)現(xiàn)PHP實(shí)現(xiàn)限制IP訪問11-11

JAVA中IP和整數(shù)相互轉(zhuǎn)化的方法07-10

設(shè)置Java對(duì)話框字體的方法06-23

關(guān)于java的訪問控制10-01