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


Java GetMethod.setRequestHeader方法代碼示例

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


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

示例1: 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

示例2: testAddRequestHeader

import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
/**
 * Test {@link HttpMethod#addRequestHeader}.
 */
public void testAddRequestHeader() throws Exception {
    this.server.setHttpService(new HeaderDumpService());
    
    GetMethod method = new GetMethod("/");
    method.setRequestHeader(new Header("addRequestHeader(Header)","True"));
    method.setRequestHeader("addRequestHeader(String,String)","Also True");
    try {
        this.client.executeMethod(method);
        String s = method.getResponseBodyAsString();
        assertTrue(s.indexOf("name=\"addrequestheader(header)\";value=\"True\"") >= 0);
        assertTrue(s.indexOf("name=\"addrequestheader(string,string)\";value=\"Also True\"") >= 0);
    } finally {
        method.releaseConnection();
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:19,代碼來源:TestHeaderOps.java

示例3: testRemoveRequestHeader

import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
/**
 * Test {@link HttpMethod#removeRequestHeader}.
 */
public void testRemoveRequestHeader() throws Exception {
    this.server.setHttpService(new HeaderDumpService());
    
    GetMethod method = new GetMethod("/");
    method.setRequestHeader(new Header("XXX-A-HEADER","true"));
    method.removeRequestHeader("XXX-A-HEADER");
    
    try {
        this.client.executeMethod(method);
        String s = method.getResponseBodyAsString();
        assertTrue(!(s.indexOf("xxx-a-header") >= 0));
    } finally {
        method.releaseConnection();
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:19,代碼來源:TestHeaderOps.java

示例4: testOverwriteRequestHeader

import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
/**
 * Test {@link HttpMethod#setRequestHeader}.
 */
public void testOverwriteRequestHeader() throws Exception {
    this.server.setHttpService(new HeaderDumpService());
    
    GetMethod method = new GetMethod("/");
    method.setRequestHeader(new Header("xxx-a-header","one"));
    method.setRequestHeader("XXX-A-HEADER","two");
    
    try {
        this.client.executeMethod(method);
        String s = method.getResponseBodyAsString();
        assertTrue(s.indexOf("name=\"xxx-a-header\";value=\"two\"") >= 0);
    } finally {
        method.releaseConnection();
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:19,代碼來源:TestHeaderOps.java

示例5: getHttpGet

import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
private static GetMethod getHttpGet(String url, String cookie,
									String userAgent) {
	GetMethod httpGet = new GetMethod(url);
	httpGet.getParams().setSoTimeout(TIMEOUT_SOCKET);
	httpGet.setRequestHeader("Connection", "Keep-Alive");
	httpGet.setRequestHeader("User-Agent", userAgent);
	return httpGet;
}
 
開發者ID:PlutoArchitecture,項目名稱:Pluto-Android,代碼行數:9,代碼來源:ApiClient.java

示例6: getResponse

import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
public MCRContent getResponse(String queryURL) throws IOException {
	// prepare http client
	HttpClient client = new HttpClient();

	// prepare GET-request
	connection = new GetMethod(queryURL);
	connection.setRequestHeader("Accept", "application/xml");

	// execute request, get response from API and return as stream
	client.executeMethod(connection);
	InputStream response = connection.getResponseBodyAsStream();
	return new MCRStreamContent(response);
}
 
開發者ID:ETspielberg,項目名稱:bibliometrics,代碼行數:14,代碼來源:ScopusConnector.java

示例7: test_multiple_ranges

import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
public void test_multiple_ranges() throws IOException {
    GetMethod get = new GetMethod(rootUrl);
    get.setRequestHeader(new Header("Range", "bytes 0-9,-10"));
    int status = httpClient.executeMethod(get);
    assertEquals("Expect 206/PARTIAL CONTENT", 206, status);

    String contentType = get.getResponseHeader("Content-Type").getValue();
    assertTrue("Content Type must be multipart/byteranges",
        contentType.contains("multipart/byteranges"));
    String boundary = contentType.substring(contentType.indexOf("boundary=")
        + "boundary=".length());

    BufferedReader reader = new BufferedReader(new InputStreamReader(
        get.getResponseBodyAsStream()));

    String line = reader.readLine();
    while (!("--" + boundary).equals(line)) {
        line = reader.readLine();
    }

    assertEquals("Expected content to start with boundary",
        "--" + boundary, line);
    assertEntityHeaders(reader, "text/plain", "bytes 0-9/79");
    assertEquals("The quick ", reader.readLine());

    assertEquals("Expected content to start with boundary",
        "--" + boundary, reader.readLine());
    assertEntityHeaders(reader, "text/plain", "bytes 69-78/79");
    assertEquals("corpus sic", reader.readLine());

    char[] buf = new char[boundary.length() + 4];
    reader.read(buf);
    assertEquals("Expected content to start with boundary", "--" + boundary
        + "--", new String(buf));
}
 
開發者ID:apache,項目名稱:sling-org-apache-sling-launchpad-integration-tests,代碼行數:36,代碼來源:RangeStreamingTest.java

示例8: testRequestCharEncoding

import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
public void testRequestCharEncoding() throws IOException {
    
    GetMethod httpget = new GetMethod("/");
    assertEquals(CHARSET_DEFAULT, httpget.getRequestCharSet());
    httpget.setRequestHeader("Content-Type", "text/plain; charset=" + CHARSET_ASCII); 
    assertEquals(CHARSET_ASCII, httpget.getRequestCharSet());
    httpget.setRequestHeader("Content-Type", "text/plain; charset=" + CHARSET_UTF8); 
    assertEquals(CHARSET_UTF8, httpget.getRequestCharSet());
    
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:11,代碼來源:TestMethodCharEncoding.java

示例9: testNoExplicitCharEncoding

import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
public void testNoExplicitCharEncoding() throws Exception {
    this.server.setHttpService(new EchoService());
    
    GetMethod httpget = new GetMethod("/test/");
    httpget.setRequestHeader("Content-Type", "text/plain"); 
    try {
        this.client.executeMethod(httpget);
        assertEquals(HttpStatus.SC_OK, httpget.getStatusCode());
        assertEquals(CHARSET_DEFAULT, httpget.getResponseCharSet());
    } finally {
        httpget.releaseConnection();
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:14,代碼來源:TestMethodCharEncoding.java

示例10: testExplicitCharEncoding

import org.apache.commons.httpclient.methods.GetMethod; //導入方法依賴的package包/類
public void testExplicitCharEncoding() throws Exception {
    this.server.setHttpService(new EchoService());
    
    GetMethod httpget = new GetMethod("/test/");
    httpget.setRequestHeader("Content-Type", "text/plain; charset=" + CHARSET_UTF8); 
    try {
        this.client.executeMethod(httpget);
        assertEquals(HttpStatus.SC_OK, httpget.getStatusCode());
        assertEquals(CHARSET_UTF8, httpget.getResponseCharSet());
    } finally {
        httpget.releaseConnection();
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:14,代碼來源:TestMethodCharEncoding.java


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