Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

18
LINES

< > BotCompany Repo | #1002941 // getURLSizeByHEAD

JavaX fragment (include)

// retrieves url with HEAD. returns content length,
// or -1 in case of error.
static long getURLSizeByHEAD(String url) {
  url = absoluteURL(url);
  HttpURLConnection conn = null;
  InputStream in = null;
  try {
    conn = (HttpURLConnection) new URL(url).openConnection();
    conn.setRequestMethod("HEAD");
    conn.setRequestProperty("X-No-Cookies", "1");
    in = conn.getInputStream();
    return conn.getContentLength();
  } catch (IOException e) {
    return -1;
  } finally {
    closeURLConnection(conn, in);
  }
}

Author comment

Began life as a copy of #1001555

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1002941
Snippet name: getURLSizeByHEAD
Eternal ID of this version: #1002941/4
Text MD5: e1731bf0b583fd8738f63680b6283626
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-12-03 23:44:45
Source code size: 544 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 694 / 656
Version history: 3 change(s)
Referenced in: #1004757 - httpSize - get size of a file behind a URL [=getURLSizeByHEAD]
#1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1009682 - getURLReturnCode - queries using HEAD, returns 200, 404 and so on
#1012490 - urlExists
#1016489 - getURLHeadersByHEAD
#1018964 - returnCodeHttpHEAD
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)