當前位置: 首頁>>代碼示例>>Java>>正文


Java URLConnection.getHeaderFieldKey方法代碼示例

本文整理匯總了Java中java.net.URLConnection.getHeaderFieldKey方法的典型用法代碼示例。如果您正苦於以下問題:Java URLConnection.getHeaderFieldKey方法的具體用法?Java URLConnection.getHeaderFieldKey怎麽用?Java URLConnection.getHeaderFieldKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.net.URLConnection的用法示例。


在下文中一共展示了URLConnection.getHeaderFieldKey方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getContentTypeHeader

import java.net.URLConnection; //導入方法依賴的package包/類
/**
 * Loops through response headers until Content-Type is found.
 * @param conn
 * @return ContentType object representing the value of
 * the Content-Type header
 */
private static ContentType getContentTypeHeader(URLConnection conn) {
    int i = 0;
    boolean moreHeaders;
    do {
        String headerName = conn.getHeaderFieldKey(i);
        String headerValue = conn.getHeaderField(i);
        if (headerName != null && headerName.equals("Content-Type"))
            return new ContentType(headerValue);

        i++;
        moreHeaders = headerName != null || headerValue != null;
    }
    while (moreHeaders);

    return null;
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:23,代碼來源:TitleExtractor.java

示例2: loadHeaders

import java.net.URLConnection; //導入方法依賴的package包/類
private void loadHeaders( URLConnection connection ) {
    if (HttpUnitOptions.isLoggingHttpHeaders()) {
        System.out.println( "Header:: " + connection.getHeaderField(0) );
    }
    for (int i = 1; true; i++) {
        String headerFieldKey = connection.getHeaderFieldKey( i );
        String headerField = connection.getHeaderField(i);
        if (headerFieldKey == null || headerField == null) break;
        if (HttpUnitOptions.isLoggingHttpHeaders()) {
            System.out.println( "Header:: " + headerFieldKey + ": " + headerField );
        }
        addHeader( headerFieldKey.toUpperCase(), headerField );
    }

    if (connection.getContentType() != null) {
        setContentTypeHeader( connection.getContentType() );
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:19,代碼來源:HttpWebResponse.java

示例3: loadHeaders

import java.net.URLConnection; //導入方法依賴的package包/類
private void loadHeaders( URLConnection connection ) {
    if (HttpUnitOptions.isLoggingHttpHeaders()) {
        System.out.println( "Header:: " + connection.getHeaderField(0) );
    }
    for (int i = 1; true; i++) {
        String key = connection.getHeaderFieldKey( i );
        if (key == null) break;
        if (HttpUnitOptions.isLoggingHttpHeaders()) {
            System.out.println( "Header:: " + connection.getHeaderFieldKey( i ) + ": " + connection.getHeaderField(i) );
        }
        addHeader( connection.getHeaderFieldKey( i ).toUpperCase(), connection.getHeaderField( i ) );
    }

    if (connection.getContentType() != null) {
        setContentTypeHeader( connection.getContentType() );
    }
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:18,代碼來源:HttpWebResponse.java

示例4: getCookieHttpClient

import java.net.URLConnection; //導入方法依賴的package包/類
/**
 * Get a cookie from Google and place it in a ClosableHttpClient
 * @return An instance of CloseableHttpClient that is critical to this Class
 * @throws IOException When URL connection is improperly formed
 */
private static CloseableHttpClient getCookieHttpClient() throws IOException {

	/*
	 * Tutorial: http://www.hccp.org/java-net-cookie-how-to.html
	 */
	URL myUrl = new URL("https://trends.google.com");
	URLConnection urlConn = myUrl.openConnection();
	urlConn.connect();

	String headerName = null;
	for(int i=1; (headerName = urlConn.getHeaderFieldKey(i)) != null; i++)
		if(headerName.equals("Set-Cookie"))
			cookieString = urlConn.getHeaderField(i);
	cookieString = cookieString.substring(0, cookieString.indexOf(";"));

	/*
	 * Tutorial: http://hc.apache.org/httpcomponents-client-ga/tutorial/html/statemgmt.html#d5e499
	 */
	CookieStore cookieStore = new BasicCookieStore();
	BasicClientCookie cookie = new BasicClientCookie("Cookie", cookieString);
	cookie.setDomain(".google.com");
	cookie.setPath("/trends");
	cookieStore.addCookie(cookie);
	return HttpClients.custom().setDefaultCookieStore(cookieStore).build();

}
 
開發者ID:Jaewan-Yun,項目名稱:Cryptocurrency-Java-Wrappers,代碼行數:32,代碼來源:GoogleTrends.java


注:本文中的java.net.URLConnection.getHeaderFieldKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。