當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。