集册 Java实例教程 从HTTP连接获取响应头

从HTTP连接获取响应头

欢马劈雪     最近更新时间:2020-01-02 10:19:05

501
从HTTP连接获取响应头
/*
 from N  o w  J a v a . c o m 
*/

import java.net.URL;

import java.net.URLConnection;


public class Main {


  public void main(String[] argv) {

    try {

      URL url = new URL("http://hostname:80");

      URLConnection conn = url.openConnection();


      // List all the response headers from the server.

      for (int i = 0;; i++) {
      /**
      nowjava.com - 时代Java
      **/

        String headerName = conn.getHeaderFieldKey(i);

        String headerValue = conn.getHeaderField(i);


        if (headerName == null && headerValue == null) {

          // No more headers

          break;

        }

        if (header
展开阅读全文