1 package net.javacoding.jspider.core.util.http; 2 3 import net.javacoding.jspider.api.model.HTTPHeader; 4 5 import java.net.URLConnection ; 6 import java.util.ArrayList ; 7 8 11 public class HTTPHeaderUtil { 12 13 public static HTTPHeader[] getHeaders ( URLConnection connection ) { 14 ArrayList arrayList = new ArrayList ( ); 15 16 String headerKey = null; 17 String headerValue = null; 18 19 int i = 0; 20 21 headerKey = connection.getHeaderFieldKey(i); 22 headerValue = connection.getHeaderField(i); 23 while ( headerKey != null || headerValue != null ) { 24 HTTPHeader header= new HTTPHeader(headerKey, headerValue ); 25 arrayList.add(header); 26 i++; 27 headerKey = connection.getHeaderFieldKey(i); 28 headerValue = connection.getHeaderField(i); 29 } 30 31 return (HTTPHeader[]) arrayList.toArray(new HTTPHeader[arrayList.size()]); 32 } 33 34 } 35 | Popular Tags |