当前位置: 首页>>代码示例>>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;未经允许,请勿转载。