当前位置: 首页>>代码示例>>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;未经允许,请勿转载。