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


Java GetMethod.addRequestHeader方法代码示例

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


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

示例1: getResource

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
/**
 * Gets remote resource.
 * 
 * @return the remove resource
 * 
 * @throws ResourceException thrown if the resource could not be fetched
 */
protected GetMethod getResource() throws ResourceException {
    GetMethod getMethod = new GetMethod(resourceUrl);
    getMethod.addRequestHeader("Connection", "close");

    try {
        httpClient.executeMethod(getMethod);
        if (getMethod.getStatusCode() != HttpStatus.SC_OK) {
            throw new ResourceException("Unable to retrieve resource URL " + resourceUrl
                    + ", received HTTP status code " + getMethod.getStatusCode());
        }
        return getMethod;
    } catch (IOException e) {
        throw new ResourceException("Unable to contact resource URL: " + resourceUrl, e);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:HttpResource.java

示例2: buildGetMethod

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
/**
 * Builds the HTTP GET method used to fetch the metadata. The returned method advertises support for GZIP and
 * deflate compression, enables conditional GETs if the cached metadata came with either an ETag or Last-Modified
 * information, and sets up basic authentication if such is configured.
 * 
 * @return the constructed GET method
 */
protected GetMethod buildGetMethod() {
    GetMethod getMethod = new GetMethod(getMetadataURI());
    getMethod.addRequestHeader("Connection", "close");

    getMethod.setRequestHeader("Accept-Encoding", "gzip,deflate");
    if (cachedMetadataETag != null) {
        getMethod.setRequestHeader("If-None-Match", cachedMetadataETag);
    }
    if (cachedMetadataLastModified != null) {
        getMethod.setRequestHeader("If-Modified-Since", cachedMetadataLastModified);
    }

    if (httpClient.getState().getCredentials(authScope) != null) {
        log.debug("Using BASIC authentication when retrieving metadata from '{}", metadataURI);
        getMethod.setDoAuthentication(true);
    }

    return getMethod;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:HTTPMetadataProvider.java

示例3: get

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public HttpResponse get(final RequestContext rq, final String scope, final int version, final String entityCollectionName, final Object entityId,
            final String relationCollectionName, final Object relationshipEntityId, Map<String, String> params, Map<String, String> headers) throws IOException
{
    if (headers == null)
    {
        headers = Collections.emptyMap();
    }

    RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), scope, version, entityCollectionName, entityId, relationCollectionName,
                relationshipEntityId, params);
    String url = endpoint.getUrl();

    GetMethod req = new GetMethod(url);

    for (Entry<String, String> header : headers.entrySet())
    {
        req.addRequestHeader(header.getKey(), header.getValue());
    }

    return submitRequest(req, rq);
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:22,代码来源:PublicApiHttpClient.java

示例4: testCustomAuthorizationHeader

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public void testCustomAuthorizationHeader() throws Exception {
    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");
    
    HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
    handlerchain.appendHandler(new AuthRequestHandler(creds));
    handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));

    this.server.setRequestHandler(handlerchain);

    GetMethod httpget = new GetMethod("/test/");
    String authResponse = "Basic " + EncodingUtil.getAsciiString(
            Base64.encodeBase64(EncodingUtil.getAsciiBytes("testuser:testpass")));
    httpget.addRequestHeader(new Header("Authorization", authResponse));
    try {
        this.client.executeMethod(httpget);
    } finally {
        httpget.releaseConnection();
    }
    assertNotNull(httpget.getStatusLine());
    assertEquals(HttpStatus.SC_OK, httpget.getStatusLine().getStatusCode());
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:23,代码来源:TestBasicAuth.java

示例5: getWithRealHeader

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public String getWithRealHeader(String url) throws IOException {
//        clearCookies();
        GetMethod g = new GetMethod(url);
        ////////////////////////
        g.addRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;");
        g.addRequestHeader("Accept-Language", "zh-cn");
        g.addRequestHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3");
        g.addRequestHeader("Keep-Alive", "300");
        g.addRequestHeader("Connection", "Keep-Alive");
        g.addRequestHeader("Cache-Control", "no-cache");
        ///////////////////////
        hc.executeMethod(g);
        return g.getResponseBodyAsString();
    }
 
开发者ID:bruceq,项目名称:Gather-Platform,代码行数:15,代码来源:HttpClientUtil.java

示例6: get

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public String get(String url, String cookies) throws
            IOException {
//        clearCookies();
        GetMethod g = new GetMethod(url);
        g.setFollowRedirects(false);
        if (StringUtils.isNotEmpty(cookies)) {
            g.addRequestHeader("cookie", cookies);
        }
        hc.executeMethod(g);
        return g.getResponseBodyAsString();
    }
 
开发者ID:bruceq,项目名称:Gather-Platform,代码行数:12,代码来源:HttpClientUtil.java

示例7: getHeader

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public String getHeader(String url, String cookies, String headername) throws IOException {
//        clearCookies();
        GetMethod g = new GetMethod(url);
        g.setFollowRedirects(false);
        if (StringUtils.isNotEmpty(cookies)) {
            g.addRequestHeader("cookie", cookies);
        }
        hc.executeMethod(g);
        return g.getResponseHeader(headername) == null ? null : g.getResponseHeader(headername).getValue();
    }
 
开发者ID:bruceq,项目名称:Gather-Platform,代码行数:11,代码来源:HttpClientUtil.java


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