第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何以編程方式下載Java網(wǎng)頁

如何以編程方式下載Java網(wǎng)頁

qq_笑_17 2019-07-06 15:27:53
如何以編程方式下載Java網(wǎng)頁我希望能夠獲取網(wǎng)頁的html并將其保存到String,這樣我就可以對它做一些處理了。此外,我如何處理各種類型的壓縮。我將如何使用Java來做這件事呢?
查看完整描述

3 回答

?
臨摹微笑

TA貢獻1982條經(jīng)驗 獲得超2個贊

Bill的回答是非常好的,但是您可能想對請求做一些事情,比如壓縮或用戶代理。下面的代碼演示如何對請求進行各種類型的壓縮。

URL url = new URL(urlStr);HttpURLConnection conn = (HttpURLConnection) url.openConnection();
 // Cast shouldn't failHttpURLConnection.setFollowRedirects(true);
 // allow both GZip and Deflate (ZLib) encodingsconn.setRequestProperty("Accept-Encoding", "gzip, deflate");
 String encoding = conn.getContentEncoding();InputStream inStr = null;
 // create the appropriate stream wrapper based on// the encoding typeif (encoding != null && encoding.equalsIgnoreCase("gzip")) {
    inStr = new GZIPInputStream(conn.getInputStream());} else if (encoding != null && encoding.equalsIgnoreCase("deflate")) {
    inStr = new InflaterInputStream(conn.getInputStream(),
      new Inflater(true));} else {
    inStr = conn.getInputStream();}

若要設(shè)置用戶代理,請?zhí)砑右韵麓a:

conn.setRequestProperty ( "User-agent", "my agent name");


查看完整回答
反對 回復 2019-07-06
  • 3 回答
  • 0 關(guān)注
  • 349 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號