熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java核心技術 >> 正文

java發送http head請求

2022-06-13   來源: Java核心技術 

  public static void main(String[] args) throws Exception {

  URL url = new URL();

  HttpURLConnection conn = (HttpURLConnection) urlopenConnection();

  // connsetDoOutput(true);

  connsetRequestMethod(HEAD);

  Map<String List<String>> headerMap = conngetHeaderFields();

  Iterator<String> iterator = headerMapkeySet(erator();

  while (iteratorhasNext()) {

  String key = iteratornext();

  List<String> values = headerMapget(key);

  Systemoutprintln(key + : + valuestoString());

  }

  }

  返回結果

  Java代碼

  null:[HTTP/ OK]

  ETag:[]

  Date:[Thu Feb :: GMT]

  ContentLength:[]

  LastModified:[Thu Jan :: GMT]

  ContentType:[text/html]

  AcceptRanges:[bytes]

  Server:[lig]


From:http://tw.wingwit.com/Article/program/Java/hx/201311/26747.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.