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

18
LINES

< > BotCompany Repo | #1009682 // getURLReturnCode - queries using HEAD, returns 200, 404 and so on

JavaX fragment (include)

1  
static int getURLReturnCode(String url) {
2  
  if (!url.contains("//")) url = "http://" + url;
3  
    
4  
  HttpURLConnection conn = null;
5  
  InputStream in = null;
6  
  try {
7  
    conn = (HttpURLConnection) new URL(url).openConnection();
8  
    conn.setRequestMethod("HEAD");
9  
    conn.setRequestProperty("X-No-Cookies", "1");
10  
    in = conn.getInputStream();
11  
    return conn.getResponseCode();
12  
  } catch (IOException e) {
13  
    silentException(e);
14  
    return -1;
15  
  } finally {
16  
    closeURLConnection(conn, in);
17  
  }
18  
}

Author comment

Began life as a copy of #1002941

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: #1009682
Snippet name: getURLReturnCode - queries using HEAD, returns 200, 404 and so on
Eternal ID of this version: #1009682/4
Text MD5: aebcd26bf86c4700c8dfd424a7c8384b
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-08-13 23:46:59
Source code size: 516 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 359 / 395
Version history: 3 change(s)
Referenced in: [show references]