当前位置: 首页>>代码示例>>Java>>正文


Java HttpURLConnection.getHeaderFieldKey方法代码示例

本文整理汇总了Java中java.net.HttpURLConnection.getHeaderFieldKey方法的典型用法代码示例。如果您正苦于以下问题:Java HttpURLConnection.getHeaderFieldKey方法的具体用法?Java HttpURLConnection.getHeaderFieldKey怎么用?Java HttpURLConnection.getHeaderFieldKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.HttpURLConnection的用法示例。


在下文中一共展示了HttpURLConnection.getHeaderFieldKey方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: storeResponseHeaders

import java.net.HttpURLConnection; //导入方法依赖的package包/类
/**
 * 保存头信息
 *
 */
private static final HashMap<String, String> storeResponseHeaders(HttpURLConnection conn) {
    if (conn == null)
        throw new NullPointerException("conn");

    HashMap<String, String> hearders = new HashMap<String, String>();

    for (int n = 0; ; ++n) {
        String key = conn.getHeaderFieldKey(n);
        if (key == null && n != 0) {
            // http恶心的地方,返回头信息第一个居然是null
            break;
        } else {
            String value = conn.getHeaderField(n);
            hearders.put(key, value);
        }
    }

    return hearders;
}
 
开发者ID:FacePlusPlus,项目名称:MegviiLicMgr-Android-SDK,代码行数:24,代码来源:HttpURLClient.java

示例2: getFileSize

import java.net.HttpURLConnection; //导入方法依赖的package包/类
public static long getFileSize(String siteUrl) {
    int nFileLength = -1;
    try {
        URL url = new URL(siteUrl);
        HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();
     httpConnection.setRequestProperty ("User-Agent", "Highter_Compute");
        int responseCode = httpConnection.getResponseCode();
        if (responseCode >= 400) {
            Utility.processErrorCode(responseCode);
            return -2;
        }
        String sHeader;
        for (int i = 1; ; i++) {
            sHeader = httpConnection.getHeaderFieldKey(i);
            if (sHeader != null) {
                if (sHeader.equals("Content-Length")) {
                    nFileLength = Integer.parseInt(httpConnection.getHeaderField(sHeader));
                    break;
                }
            } else
                break;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    Utility.log(String.format("Length of the file: %d", nFileLength));
    return nFileLength;
}
 
开发者ID:Luodian,项目名称:Higher-Cloud-Computing-Project,代码行数:29,代码来源:FileInfo.java

示例3: connectionMade

import java.net.HttpURLConnection; //导入方法依赖的package包/类
@Override
public void connectionMade(URLConnection connection)
{
	if( connection instanceof HttpURLConnection )
	{
		HttpURLConnection httpcon = (HttpURLConnection) connection;

		StringBuffer headerBuf = new StringBuffer();
		int headerCount = 1;
		boolean done = false;
		while( !done )
		{
			String headerKey = httpcon.getHeaderFieldKey(headerCount);
			if( headerKey != null )
			{
				String headerVal = httpcon.getHeaderField(headerCount);

				boolean found = false;
				LOGGER.debug(headerKey + " :: " + headerVal);
				for( int i = 0; i < SEEK_FOR_HEADERS.length && !found; i++ )
				{

					if( headerKey.equalsIgnoreCase(SEEK_FOR_HEADERS[i]) )
					{
						headerBuf.append('<').append(headerKey).append(": ").append(headerVal).append('>');
						found = true;
					}
				}
			}
			else
			{
				done = true;
			}
			headerCount++;
		}

		if( headerBuf.indexOf("MISS") >= 0 )
		{
			LOGGER.debug("URL Not Cached: " + headerBuf);
		}
	}
	else
	{
		LOGGER.debug("Headers could not be retrieved: Not a HTTP Connection");
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:47,代码来源:Service.java

示例4: downloadXmlAsStream

import java.net.HttpURLConnection; //导入方法依赖的package包/类
private static InputStream downloadXmlAsStream(Context context, URL url, String userAgent,
                                               String cookie, Map<String, String>
                                                       requestHdrs, HttpHeaderInfo
                                                       responseHdrs) throws IOException {
    if (context == null) {
        throw new IllegalArgumentException("context");
    } else if (url == null) {
        throw new IllegalArgumentException("url");
    } else {
        InputStream inputStream;
        URL newUrl = url;
        HttpsURLConnection.setDefaultHostnameVerifier(ignoreHostnameVerifier);
        HttpURLConnection.setFollowRedirects(true);
        HttpURLConnection conn = getHttpUrlConnection(context, newUrl);
        conn.setConnectTimeout(10000);
        conn.setReadTimeout(15000);
        TrustManager[] tm = new TrustManager[]{ignoreCertificationTrustManger};
        SSLContext sslContext = null;
        try {
            sslContext = SSLContext.getInstance("SSL");
            sslContext.init(null, tm, new SecureRandom());
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (KeyManagementException e2) {
            e2.printStackTrace();
        }
        ((HttpsURLConnection) conn).setSSLSocketFactory(sslContext.getSocketFactory());
        if (!TextUtils.isEmpty(userAgent)) {
            conn.setRequestProperty(USER_AGENT, userAgent);
        }
        if (cookie != null) {
            conn.setRequestProperty("Cookie", cookie);
        }
        if (requestHdrs != null) {
            for (String key : requestHdrs.keySet()) {
                conn.setRequestProperty(key, (String) requestHdrs.get(key));
            }
        }
        if (responseHdrs != null && (url.getProtocol().equals("http") || url.getProtocol()
                .equals(b.a))) {
            responseHdrs.ResponseCode = conn.getResponseCode();
            if (responseHdrs.AllHeaders == null) {
                responseHdrs.AllHeaders = new HashMap();
            }
            int i = 0;
            while (true) {
                String name = conn.getHeaderFieldKey(i);
                String value = conn.getHeaderField(i);
                if (name == null && value == null) {
                    break;
                }
                if (!(TextUtils.isEmpty(name) || TextUtils.isEmpty(value))) {
                    responseHdrs.AllHeaders.put(name, value);
                }
                i++;
            }
        }
        try {
            inputStream = conn.getInputStream();
        } catch (IOException e3) {
            inputStream = conn.getErrorStream();
        }
        return new DoneHandlerInputStream(inputStream);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:66,代码来源:Network.java


注:本文中的java.net.HttpURLConnection.getHeaderFieldKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。