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


Java BasicHttpEntityEnclosingRequest.addHeader方法代碼示例

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


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

示例1: testResponsesToPUTsAreNotCached

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void testResponsesToPUTsAreNotCached() throws Exception {
    emptyMockCacheExpectsNoPuts();

    final BasicHttpEntityEnclosingRequest put = new BasicHttpEntityEnclosingRequest("PUT", "/",
            HttpVersion.HTTP_1_1);
    put.setEntity(HttpTestUtils.makeBody(128));
    put.addHeader("Content-Length", "128");

    originResponse.setHeader("Cache-Control", "max-age=3600");

    EasyMock.expect(
            mockBackend.execute(
                    EasyMock.isA(HttpRoute.class),
                    EasyMock.isA(HttpRequestWrapper.class),
                    EasyMock.isA(HttpClientContext.class),
                    EasyMock.<HttpExecutionAware>isNull())).andReturn(originResponse);

    replayMocks();

    impl.execute(route, HttpRequestWrapper.wrap(put), context, null);

    verifyMocks();
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:25,代碼來源:TestProtocolRequirements.java

示例2: createRealRequest

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入方法依賴的package包/類
/**
 * Creates a request that can be accepted by the AndroidHttpClient
 * @param request The request information
 * @throws UnsupportedEncodingException
 */
private static BasicHttpEntityEnclosingRequest createRealRequest(Request request) throws UnsupportedEncodingException {
	BasicHttpEntityEnclosingRequest realRequest = new BasicHttpEntityEnclosingRequest(request.getVerb(), request.getUrl());

	if (request.getContent() != null) {
		realRequest.setEntity(new ByteArrayEntity(request.getContent()));
	}

	Map<String, String> headers = request.getHeaders();

	for (String key : headers.keySet()) {
		realRequest.addHeader(key, headers.get(key));
	}

	return realRequest;
}
 
開發者ID:ashank,項目名稱:Office-365-SDK-for-Android,代碼行數:21,代碼來源:FroyoHttpConnection.java

示例3: testOrderOfMultipleAllowHeadersIsPreservedOnRequests

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void testOrderOfMultipleAllowHeadersIsPreservedOnRequests() throws Exception {
    final BasicHttpEntityEnclosingRequest put = new BasicHttpEntityEnclosingRequest("PUT", "/",
            HttpVersion.HTTP_1_1);
    put.setEntity(body);
    put.addHeader("Allow", "GET, HEAD");
    put.addHeader("Allow", "DELETE");
    put.addHeader("Content-Length", "128");
    testOrderOfMultipleHeadersIsPreservedOnRequests("Allow", HttpRequestWrapper.wrap(put));
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:11,代碼來源:TestProtocolRequirements.java

示例4: testOrderOfMultipleContentEncodingHeadersIsPreservedOnRequests

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void testOrderOfMultipleContentEncodingHeadersIsPreservedOnRequests() throws Exception {
    final BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest("POST", "/",
            HttpVersion.HTTP_1_1);
    post.setEntity(body);
    post.addHeader("Content-Encoding", "gzip");
    post.addHeader("Content-Encoding", "compress");
    post.addHeader("Content-Length", "128");
    testOrderOfMultipleHeadersIsPreservedOnRequests("Content-Encoding", HttpRequestWrapper.wrap(post));
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:11,代碼來源:TestProtocolRequirements.java

示例5: testOrderOfMultipleContentLanguageHeadersIsPreservedOnRequests

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void testOrderOfMultipleContentLanguageHeadersIsPreservedOnRequests() throws Exception {
    final BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest("POST", "/",
            HttpVersion.HTTP_1_1);
    post.setEntity(body);
    post.addHeader("Content-Language", "mi");
    post.addHeader("Content-Language", "en");
    post.addHeader("Content-Length", "128");
    testOrderOfMultipleHeadersIsPreservedOnRequests("Content-Language", HttpRequestWrapper.wrap(post));
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:11,代碼來源:TestProtocolRequirements.java

示例6: testOrderOfMultipleExpectHeadersIsPreservedOnRequests

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void testOrderOfMultipleExpectHeadersIsPreservedOnRequests() throws Exception {
    final BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest("POST", "/",
            HttpVersion.HTTP_1_1);
    post.setEntity(body);
    post.addHeader("Expect", "100-continue");
    post.addHeader("Expect", "x-expect=true");
    post.addHeader("Content-Length", "128");
    testOrderOfMultipleHeadersIsPreservedOnRequests("Expect", HttpRequestWrapper.wrap(post));
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:11,代碼來源:TestProtocolRequirements.java

示例7: getCoapRequestPayloadTest

import org.apache.http.message.BasicHttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public final void getCoapRequestPayloadTest() throws TranslationException {
	String coapServerUri = "coap://coapServer:5684/helloWorld";

	for (String httpMethod : COAP_METHODS) {
		// create the http request
		RequestLine requestLine = new BasicRequestLine(httpMethod, "/" + PROXY_RESOURCE + "/" + coapServerUri, HttpVersion.HTTP_1_1);
		BasicHttpEntityEnclosingRequest httpRequest = new BasicHttpEntityEnclosingRequest(requestLine);

		// create the entity
		String contentString = "aaa";
		HttpEntity httpEntity = new ByteArrayEntity(contentString.getBytes(Charset.forName("ISO_8859_1")), ContentType.TEXT_PLAIN);
		httpRequest.setEntity(httpEntity);

		// set the content-type
		httpRequest.setHeader("content-type", "text/plain;  charset=iso-8859-1");

		// create the header
		String headerName = "if-match";
		String headerValue = "\"737060cd8c284d8af7ad3082f209582d\"";
		Header header = new BasicHeader(headerName, headerValue);
		httpRequest.addHeader(header);

		// translate the request
		Request coapRequest = HttpTranslator.getCoapRequest(httpRequest, PROXY_RESOURCE, true);
		assertNotNull(httpRequest);

		// check the method translation
		int coapMethod = Integer.parseInt(HttpTranslator.HTTP_TRANSLATION_PROPERTIES.getProperty("http.request.method." + httpMethod));
		assertTrue(coapRequest.getCode() == coapMethod);

		// check the proxy-uri
		String proxyUri = coapRequest.getFirstOption(OptionNumberRegistry.PROXY_URI).getStringValue();
		assertEquals(proxyUri, coapServerUri);

		// check the absence of the uri-* options
		assertNull(coapRequest.getFirstOption(OptionNumberRegistry.URI_PATH));
		assertNull(coapRequest.getFirstOption(OptionNumberRegistry.URI_HOST));
		assertNull(coapRequest.getFirstOption(OptionNumberRegistry.URI_QUERY));
		assertNull(coapRequest.getFirstOption(OptionNumberRegistry.URI_PORT));

		// check the payload
		assertNotNull(coapRequest.getPayload());
		assertArrayEquals(contentString.getBytes(Charset.forName("UTF-8")), coapRequest.getPayload());

		// check the option
		assertFalse(coapRequest.getOptions().isEmpty());
		int optionNumber = Integer.parseInt(HttpTranslator.HTTP_TRANSLATION_PROPERTIES.getProperty("http.message.header." + headerName));
		assertEquals(coapRequest.getFirstOption(optionNumber).getStringValue(), headerValue);

		// check the content-type
		assertEquals(coapRequest.getContentType(), MediaTypeRegistry.TEXT_PLAIN);
	}
}
 
開發者ID:Orange-OpenSource,項目名稱:holico,代碼行數:55,代碼來源:HttpTranslatorTest.java


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