当前位置: 首页>>代码示例>>Java>>正文


Java HttpResponse.getAllHeaders方法代码示例

本文整理汇总了Java中org.apache.http.HttpResponse.getAllHeaders方法的典型用法代码示例。如果您正苦于以下问题:Java HttpResponse.getAllHeaders方法的具体用法?Java HttpResponse.getAllHeaders怎么用?Java HttpResponse.getAllHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.HttpResponse的用法示例。


在下文中一共展示了HttpResponse.getAllHeaders方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRedirect

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
/**
 * get a redirect for an url: this method shall be called if it is expected that a url
 * is redirected to another url. This method then discovers the redirect.
 * @param urlstring
 * @param useAuthentication
 * @return the redirect url for the given urlstring
 * @throws IOException if the url is not redirected
 */
public static String getRedirect(String urlstring) throws IOException {
    HttpGet get = new HttpGet(urlstring);
    get.setConfig(RequestConfig.custom().setRedirectsEnabled(false).build());
    get.setHeader("User-Agent", ClientIdentification.getAgent(ClientIdentification.yacyInternetCrawlerAgentName).userAgent);
    CloseableHttpClient httpClient = getClosableHttpClient();
    HttpResponse httpResponse = httpClient.execute(get);
    HttpEntity httpEntity = httpResponse.getEntity();
    if (httpEntity != null) {
        if (httpResponse.getStatusLine().getStatusCode() == 301) {
            for (Header header: httpResponse.getAllHeaders()) {
                if (header.getName().equalsIgnoreCase("location")) {
                    EntityUtils.consumeQuietly(httpEntity);
                    return header.getValue();
                }
            }
            EntityUtils.consumeQuietly(httpEntity);
            throw new IOException("redirect for  " + urlstring+ ": no location attribute found");
        } else {
            EntityUtils.consumeQuietly(httpEntity);
            throw new IOException("no redirect for  " + urlstring+ " fail: " + httpResponse.getStatusLine().getStatusCode() + ": " + httpResponse.getStatusLine().getReasonPhrase());
        }
    } else {
        throw new IOException("client connection to " + urlstring + " fail: no connection");
    }
}
 
开发者ID:yacy,项目名称:yacy_grid_mcp,代码行数:34,代码来源:ClientConnection.java

示例2: HttpResult

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
public HttpResult(HttpResponse httpResponse, CookieStore cookieStore) {
	if (cookieStore != null) {
		this.cookies = cookieStore.getCookies().toArray(new Cookie[0]);
	}

	if (httpResponse != null) {
		this.headers = httpResponse.getAllHeaders();
		this.statuCode = httpResponse.getStatusLine().getStatusCode();
		if(d)System.out.println(this.statuCode);
		try {
			this.response = EntityUtils.toByteArray(httpResponse
					.getEntity());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
 
开发者ID:Evan-Galvin,项目名称:FreeStreams-TVLauncher,代码行数:19,代码来源:HttpResult.java

示例3: Response

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
/**
 * Constructor
 *
 * @param response the http response
 */
public Response( final HttpResponse response )
{
	this.status = response.getStatusLine( );
	this.headers = response.getAllHeaders( );

	try
	{
		this.entityContent = EntityUtils.toByteArray( response.getEntity( ) );
		// EntityUtils.consume( response.getEntity( ) );
	}
	catch ( IllegalArgumentException | IOException e )
	{
		// ok
	}
}
 
开发者ID:ApinautenGmbH,项目名称:integration-test-helper,代码行数:21,代码来源:Response.java

示例4: logResponse

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
private LogInstance logResponse( LogInstance logInstance, HttpResponse response, String respBody ) {
    if( response != null ) {
        logInstance.setRespHttpStatus( response.getStatusLine().getStatusCode() );

        // log request headers and body?
        for( Header header : response.getAllHeaders() ) {
            if( logLevel == LogLevel.TRACE || header.getName().toLowerCase().equals( "x-gateway-site-id" ) || header.getName().toLowerCase().equals( "x-request-uuid" ) ) {
                logInstance.addRespHeader( header.getName(), header.getValue() );
            }
        }

        if( logLevel == LogLevel.TRACE ) {
            if( respBody != null ) {
                String logRespBody;
                if( respBody.length() > REQUEST_AND_RESPONSE_BODY_LOG_MAX_LENGTH ) {
                    logRespBody = respBody.substring( 0, REQUEST_AND_RESPONSE_BODY_LOG_MAX_LENGTH ) + "...response body truncated...";
                }
                else logRespBody = respBody;

                logInstance.setRespBody( logRespBody );
            }
       }
    }
    return logInstance;
}
 
开发者ID:tenable,项目名称:Tenable.io-SDK-for-Java,代码行数:26,代码来源:HttpFuture.java

示例5: toFeignResponse

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
Response toFeignResponse(HttpResponse httpResponse) throws IOException {
  StatusLine statusLine = httpResponse.getStatusLine();
  int statusCode = statusLine.getStatusCode();

  String reason = statusLine.getReasonPhrase();

  Map<String, Collection<String>> headers = new HashMap<String, Collection<String>>();
  for (Header header : httpResponse.getAllHeaders()) {
    String name = header.getName();
    String value = header.getValue();

    Collection<String> headerValues = headers.get(name);
    if (headerValues == null) {
      headerValues = new ArrayList<String>();
      headers.put(name, headerValues);
    }
    headerValues.add(value);
  }

  return Response.builder()
          .status(statusCode)
          .reason(reason)
          .headers(headers)
          .body(toFeignBody(httpResponse))
          .build();
}
 
开发者ID:wenwu315,项目名称:XXXX,代码行数:27,代码来源:ApacheHttpClient.java

示例6: convert

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
private static Response convert(HttpResponse response) throws IOException {
	Response res = new Response(); 
	
	if (null != response) {
		res.setStatusCode(response.getStatusLine().getStatusCode());
		for (Header header : response.getAllHeaders()) {
			res.setHeader(header.getName(), MessageDigestUtil.iso88591ToUtf8(header.getValue()));
        }
		
		res.setContentType(res.getHeader("Content-Type"));
		res.setRequestId(res.getHeader("X-Ca-Request-Id"));
		res.setErrorMessage(res.getHeader("X-Ca-Error-Message"));
		res.setBody(readStreamAsStr(response.getEntity().getContent()));
		
	} else {
		//服务器无回应
		res.setStatusCode(500);
		res.setErrorMessage("No Response");
	}
	
	return res;
}
 
开发者ID:linkingli,项目名称:FaceDistinguish,代码行数:23,代码来源:HttpUtil.java

示例7: a

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
private static boolean a(HttpResponse httpResponse) {
    String str = null;
    String str2 = a;
    if (httpResponse != null) {
        Header[] allHeaders = httpResponse.getAllHeaders();
        if (allHeaders != null && allHeaders.length > 0) {
            for (Header header : allHeaders) {
                if (header != null) {
                    String name = header.getName();
                    if (name != null && name.equalsIgnoreCase(str2)) {
                        str = header.getValue();
                        break;
                    }
                }
            }
        }
    }
    return Boolean.valueOf(str).booleanValue();
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:20,代码来源:d.java

示例8: onReceive

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
@Override
public void onReceive(TransportContext context) {
	super.onReceive(context);
	if (token == null) {
		if (!(context instanceof HttpTransportContext))
			return;

		HttpResponse response = ((HttpTransportContext) context)
				.getHttpResponse();

		Header[] headers = response.getAllHeaders();
		for (Header h : headers) {
			if (h.getName().equals("set-cookie")) {
				token = h.getValue();
			}
		}
	}
}
 
开发者ID:Esri,项目名称:defense-solutions-proofs-of-concept,代码行数:19,代码来源:MLOBIOutboundTransport.java

示例9: extractResponseHeaders

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
Map<String, String> extractResponseHeaders(final HttpResponse httpResponse) {

        return new HashMap<String, String>() {
            {
                for (Header h : httpResponse.getAllHeaders()) {
                    put(h.getName(), h.getValue());
                }
            }
        };
    }
 
开发者ID:mgtechsoftware,项目名称:smockin,代码行数:11,代码来源:HttpClientServiceImpl.java

示例10: receiveResponseHeader

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
@Override
public HttpResponse receiveResponseHeader() throws HttpException, IOException {
    HttpResponse response = super.receiveResponseHeader();
    if (log.isDebugEnabled()) {
        log.debug("Receiving response: " + response.getStatusLine());
    }
    if (headerLog.isDebugEnabled()) {
        headerLog.debug("<< " + response.getStatusLine().toString());
        Header[] headers = response.getAllHeaders();
        for (Header header : headers) {
            headerLog.debug("<< " + header.toString());
        }
    }
    return response;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:16,代码来源:DefaultClientConnection.java

示例11: doReceiveResponse

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
@Override
protected HttpResponse doReceiveResponse(final HttpRequest request, final HttpClientConnection conn, final HttpContext context) throws HttpException, IOException {
    final HttpResponse response = super.doReceiveResponse(request, conn, context);
    synchronized(listener) {
        listener.log(TranscriptListener.Type.response, response.getStatusLine().toString());
        for(Header header : response.getAllHeaders()) {
            listener.log(TranscriptListener.Type.response, header.toString());
        }
    }
    return response;
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:12,代码来源:LoggingHttpRequestExecutor.java

示例12: headers

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
public static Map<String,String> headers(KeyPair keyPair,String url) {
    Map<String,String> headerMap = new HashMap<>();
    URI uri = buildUri(url,null);
    if(uri == null) {
        return headerMap;
    }
    url = uri.toString();
    log.info("get url:{}",url);

    Request request = Request.Get(url);

    configRequest(request,Constant.METHOD_GET,keyPair,null,"");

    try {
        HttpResponse httpResponse = request.execute()
                .returnResponse();
        Header[] allHeaders = httpResponse.getAllHeaders();

        for (Header header :
                allHeaders) {
            headerMap.put(header.getName(),header.getValue());
        }
    } catch (IOException e) {
        e.printStackTrace();
    }


    return headerMap;
}
 
开发者ID:Liangdi,项目名称:zaoshu-java-sdk,代码行数:30,代码来源:HttpUtil.java

示例13: HttpResponseBody

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
HttpResponseBody(HttpResponse response,OnHttpErrorListener listener){
    mOnHttpErrorListener = listener;
    stateCode = response.getStatusLine().getStatusCode();
    headers = response.getAllHeaders();
    bytes = bytes(response.getEntity());
    if(QuickHttpController.isDebug){
        QuickHttpController.log("Response content : "+ text());
    }
}
 
开发者ID:fcibook,项目名称:QuickHttp,代码行数:10,代码来源:HttpResponseBody.java

示例14: a

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
private static HttpUrlHeader a(HttpResponse httpResponse) {
    HttpUrlHeader httpUrlHeader = new HttpUrlHeader();
    for (Header header : httpResponse.getAllHeaders()) {
        httpUrlHeader.setHead(header.getName(), header.getValue());
    }
    return httpUrlHeader;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:8,代码来源:q.java

示例15: copyResponseHeaders

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
/** Copy proxied response headers back to the servlet client. */
protected void copyResponseHeaders(HttpResponse proxyResponse, HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
    for (Header header : proxyResponse.getAllHeaders()) {
        if (hopByHopHeaders.containsHeader(header.getName()))
            continue;
        if (header.getName().equalsIgnoreCase(org.apache.http.cookie.SM.SET_COOKIE)
                || header.getName().equalsIgnoreCase(org.apache.http.cookie.SM.SET_COOKIE2)) {
            copyProxyCookie(servletRequest, servletResponse, header);
        } else {
            servletResponse.addHeader(header.getName(), header.getValue());
        }
    }
}
 
开发者ID:bluecreator,项目名称:http-agent,代码行数:14,代码来源:AgentServlet.java


注:本文中的org.apache.http.HttpResponse.getAllHeaders方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。