本文整理汇总了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");
}
}
示例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();
}
}
}
示例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
}
}
示例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;
}
示例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();
}
示例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;
}
示例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();
}
示例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();
}
}
}
}
示例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());
}
}
};
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
}
示例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;
}
示例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());
}
}
}