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


Java HttpResponse.addHeader方法代碼示例

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


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

示例1: executePost

import org.apache.http.HttpResponse; //導入方法依賴的package包/類
/**
 * Выполнить Post запрос
 * 
 * @param <T>
 *            класс ответа {@link ru.maksimov.andrey.golos4j.dto.api}
 * 
 * @param method
 *            объект который нужно отпрапвить в запросе
 * @param classDto
 *            класс возврата
 * @param url
 *            url адрес
 * @return дата в заданном формате
 * @throws SystemException
 *             система ошибка выполения запроса
 */
public static <T> T executePost(BaseMethod method, Class<T> classDto, String url) throws SystemException {
	SSLContext sslContext = Util.getSSLContext();
	RequestConfig config = Util.getConfig(connectTimeout, connectionRequestTimeout, socketTimeout);
	CloseableHttpClient httpClient = HttpClientBuilder.create().setSSLContext(sslContext)
			.setDefaultRequestConfig(config).build();
	HttpPost httpPost = new HttpPost(url);
	httpPost.setEntity(method.getEntity());
	httpPost.addHeader("Content-Type", APPLICATION_JSON_UTF8_VALUE);
	try {
		HttpResponse response = httpClient.execute(httpPost);
		response.addHeader("Content-Type", APPLICATION_JSON_UTF8_VALUE);
		HttpEntity entity = response.getEntity();

		LOG.debug("Content: " + entity.getContent());
		if (entity != null) {
			LOG.debug("Response content length: " + entity.getContentLength());
		}
		ObjectMapper mapper = new ObjectMapper();
		String jsonString = EntityUtils.toString(entity, ENCODING_CHARSET);
		LOG.debug("Response content: " + jsonString);
		T getDto = mapper.readValue(jsonString, classDto);
		return getDto;
	} catch (ClientProtocolException cpe) {
		throw new SystemException("Unable execute send POST-request: " + cpe.getMessage(), cpe);
	} catch (IOException ioe) {
		throw new SystemException("Unable execute POST-request: " + ioe.getMessage(), ioe);
	}
}
 
開發者ID:onixred,項目名稱:golos4j,代碼行數:45,代碼來源:Util.java

示例2: process

import org.apache.http.HttpResponse; //導入方法依賴的package包/類
public void process(final HttpResponse response, final HttpContext context)
        throws HttpException, IOException {
    if (response == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }
    if (!response.containsHeader(HTTP.SERVER_HEADER)) {
        String s = (String) response.getParams().getParameter(
                CoreProtocolPNames.ORIGIN_SERVER);
        if (s != null) {
            response.addHeader(HTTP.SERVER_HEADER, s);
        }
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:14,代碼來源:ResponseServer.java

示例3: handle

import org.apache.http.HttpResponse; //導入方法依賴的package包/類
@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context)
        throws HttpException, IOException {

    response.setStatusCode(HttpStatus.SC_MOVED_PERMANENTLY);
    response.addHeader("Location", PropagationHandler.MAPPING);
}
 
開發者ID:opentracing-contrib,項目名稱:java-apache-httpclient,代碼行數:8,代碼來源:TracingHttpClientBuilderTest.java

示例4: build

import org.apache.http.HttpResponse; //導入方法依賴的package包/類
public static DummyResponseServerBehavior build(int statusCode, String statusMessage, String content) {
    HttpResponse response = new BasicHttpResponse(
            new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), statusCode, statusMessage));
    setEntity(response, content);
    response.addHeader("Content-Length", String.valueOf(content.getBytes().length));
    response.addHeader("Connection", "close");
    return new DummyResponseServerBehavior(response);
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:9,代碼來源:MockServer.java

示例5: testPostAuthForCookie

import org.apache.http.HttpResponse; //導入方法依賴的package包/類
/**
 * Tests the authentication post.
 */
private void testPostAuthForCookie(int responseStatus, String headerName, boolean isValidUser) throws IOException
{
  HttpResponse fakeHttpResponse = new BasicHttpResponse(HttpVersion.HTTP_1_1, responseStatus, "some reason");
  fakeHttpResponse.addHeader(headerName, COOKIE_VALUE);
  fakeHttpResponse.setEntity(new StringEntity("{\"isLoggedIn\": " + isValidUser + "}"));
  when(mockResponse.returnResponse()).thenReturn(fakeHttpResponse);
  NameValuePair[] authParams = new NameValuePair[] {
      new BasicNameValuePair("auth1", "hello"),
      new BasicNameValuePair("auth2", "world")
  };

  httpHelper.postAuthForCookie(mockExecutor, URI, authParams);
}
 
開發者ID:Nike-Inc,項目名稱:bluegreen-manager,代碼行數:17,代碼來源:HttpHelperTest.java

示例6: getResponse

import org.apache.http.HttpResponse; //導入方法依賴的package包/類
@Override
public HttpResponse getResponse(Request r) throws IOException {
    HttpResponse response = parentAction.getResponse(r);
    response.addHeader(name, value);
    return response;
}
 
開發者ID:PawelAdamski,項目名稱:HttpClientMock,代碼行數:7,代碼來源:HeaderAction.java

示例7: process

import org.apache.http.HttpResponse; //導入方法依賴的package包/類
/**
 * Processes the response (possibly updating or inserting) Content-Length and Transfer-Encoding headers.
 * @param response The HttpResponse to modify.
 * @param context Unused.
 * @throws ProtocolException If either the Content-Length or Transfer-Encoding headers are found.
 * @throws IllegalArgumentException If the response is null.
 */
public void process(final HttpResponse response, final HttpContext context)
        throws HttpException, IOException {
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }
    if (this.overwrite) {
        response.removeHeaders(HTTP.TRANSFER_ENCODING);
        response.removeHeaders(HTTP.CONTENT_LEN);
    } else {
        if (response.containsHeader(HTTP.TRANSFER_ENCODING)) {
            throw new ProtocolException("Transfer-encoding header already present");
        }
        if (response.containsHeader(HTTP.CONTENT_LEN)) {
            throw new ProtocolException("Content-Length header already present");
        }
    }
    ProtocolVersion ver = response.getStatusLine().getProtocolVersion();
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        long len = entity.getContentLength();
        if (entity.isChunked() && !ver.lessEquals(HttpVersion.HTTP_1_0)) {
            response.addHeader(HTTP.TRANSFER_ENCODING, HTTP.CHUNK_CODING);
        } else if (len >= 0) {
            response.addHeader(HTTP.CONTENT_LEN, Long.toString(entity.getContentLength()));
        }
        // Specify a content type if known
        if (entity.getContentType() != null && !response.containsHeader(
                HTTP.CONTENT_TYPE )) {
            response.addHeader(entity.getContentType());
        }
        // Specify a content encoding if known
        if (entity.getContentEncoding() != null && !response.containsHeader(
                HTTP.CONTENT_ENCODING)) {
            response.addHeader(entity.getContentEncoding());
        }
    } else {
        int status = response.getStatusLine().getStatusCode();
        if (status != HttpStatus.SC_NO_CONTENT
                && status != HttpStatus.SC_NOT_MODIFIED
                && status != HttpStatus.SC_RESET_CONTENT) {
            response.addHeader(HTTP.CONTENT_LEN, "0");
        }
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:52,代碼來源:ResponseContent.java


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