當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。