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


Java HttpResponse.getFirstHeader方法代码示例

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


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

示例1: sendResponseMessage

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
public void sendResponseMessage(HttpResponse response) throws IOException {
    if (!Thread.currentThread().isInterrupted()) {
        StatusLine status = response.getStatusLine();
        if (status.getStatusCode() == 416) {
            if (!Thread.currentThread().isInterrupted()) {
                sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), null);
            }
        } else if (status.getStatusCode() >= 300) {
            if (!Thread.currentThread().isInterrupted()) {
                sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), null,
                        new HttpResponseException(status.getStatusCode(), status
                                .getReasonPhrase()));
            }
        } else if (!Thread.currentThread().isInterrupted()) {
            Header header = response.getFirstHeader(AsyncHttpClient.HEADER_CONTENT_RANGE);
            if (header == null) {
                this.append = false;
                this.current = 0;
            } else {
                Log.v(LOG_TAG, "Content-Range: " + header.getValue());
            }
            sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(),
                    getResponseData(response.getEntity()));
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:27,代码来源:RangeFileAsyncHttpResponseHandler.java

示例2: sendResponseMessage

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
@Override
public void sendResponseMessage(HttpResponse response) throws IOException {
    if (!Thread.currentThread().isInterrupted()) {
        StatusLine status = response.getStatusLine();
        if (status.getStatusCode() == HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE) {
            //already finished
            if (!Thread.currentThread().isInterrupted())
                sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), null);
        } else if (status.getStatusCode() >= 300) {
            if (!Thread.currentThread().isInterrupted())
                sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), null, new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()));
        } else {
            if (!Thread.currentThread().isInterrupted()) {
                Header header = response.getFirstHeader(AsyncHttpClient.HEADER_CONTENT_RANGE);
                if (header == null) {
                    append = false;
                    current = 0;
                } else
                    Log.v(LOG_TAG, AsyncHttpClient.HEADER_CONTENT_RANGE + ": " + header.getValue());
                sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), getResponseData(response.getEntity()));
            }
        }
    }
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:25,代码来源:RangeFileAsyncHttpResponseHandler.java

示例3: getLocationHeader

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
/**
 * Get the first 'Location' header and verify it's a valid URI.
 *
 * @param response HttpResponse the http response
 * @return the location path
 * @throws ClientException never (kept for uniformity)
 */
public static String getLocationHeader(HttpResponse response) throws ClientException {
    if (response == null) throw new ClientException("Response must not be null!");

    String locationPath = null;
    Header locationHeader = response.getFirstHeader("Location");
    if (locationHeader != null) {
        String location = locationHeader.getValue();
        URI locationURI = URI.create(location);
        locationPath = locationURI.getPath();
    }

    if (locationPath == null) {
        throw new ClientException("not able to determine location path");
    }
    return locationPath;
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-testing-clients,代码行数:24,代码来源:HttpUtils.java

示例4: isRedirected

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
public boolean isRedirected(
        final HttpRequest request,
        final HttpResponse response,
        final HttpContext context) throws ProtocolException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }

    int statusCode = response.getStatusLine().getStatusCode();
    String method = request.getRequestLine().getMethod();
    Header locationHeader = response.getFirstHeader("location");
    switch (statusCode) {
    case HttpStatus.SC_MOVED_TEMPORARILY:
        return isRedirectable(method) && locationHeader != null;
    case HttpStatus.SC_MOVED_PERMANENTLY:
    case HttpStatus.SC_TEMPORARY_REDIRECT:
        return isRedirectable(method);
    case HttpStatus.SC_SEE_OTHER:
        return true;
    default:
        return false;
    } //end of switch
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:DefaultRedirectStrategy.java

示例5: getContent

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
@Override
protected String getContent(String charset, HttpResponse httpResponse) throws IOException {
    if (charset == null) {
        long contentLength = httpResponse.getEntity().getContentLength();
        if (httpResponse.getFirstHeader("Content-Type") != null && !httpResponse.getFirstHeader("Content-Type").getValue().toLowerCase().contains("text/html")) {
            throw new IllegalArgumentException("本链接为非HTML内容,不下载,内容类型为:" + httpResponse.getFirstHeader("Content-Type"));
        } else if (contentLength > staticValue.getMaxHttpDownloadLength()) {
            throw new IllegalArgumentException("HTTP内容长度超过限制,实际大小为:" + contentLength + ",限制最大值为:" + staticValue.getMaxHttpDownloadLength());
        }
        byte[] contentBytes = IOUtils.toByteArray(httpResponse.getEntity().getContent());
        String htmlCharset = getHtmlCharset(httpResponse, contentBytes);
        if (htmlCharset != null) {
            return new String(contentBytes, htmlCharset);
        } else {
            LOG.warn("Charset autodetect failed, use {} as charset. Please specify charset in Site.setCharset()", Charset.defaultCharset());
            return new String(contentBytes);
        }
    } else {
        return IOUtils.toString(httpResponse.getEntity().getContent(), charset);
    }
}
 
开发者ID:bruceq,项目名称:Gather-Platform,代码行数:22,代码来源:ContentLengthLimitHttpClientDownloader.java

示例6: saveInfo

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
/**
 * Saves part of the HTTP Response to the info file.
 */
private void saveInfo(
        @NonNull String urlString,
        @NonNull HttpResponse response,
        @NonNull File info) throws IOException {
    Properties props = new Properties();

    // we don't need the status code & URL right now.
    // Save it in case we want to have it later (e.g. to differentiate 200 and 404.)
    props.setProperty(KEY_URL, urlString);
    props.setProperty(KEY_STATUS_CODE,
            Integer.toString(response.getStatusLine().getStatusCode()));

    for (String name : INFO_HTTP_HEADERS) {
        Header h = response.getFirstHeader(name);
        if (h != null) {
            props.setProperty(name, h.getValue());
        }
    }

    mFileOp.saveProperties(info, props, "## Meta data for SDK Manager cache. Do not modify."); //$NON-NLS-1$
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:25,代码来源:DownloadCache.java

示例7: sendResponseMessage

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
@Override
public void sendResponseMessage(HttpResponse response) throws IOException {
    if (!Thread.currentThread().isInterrupted()) {
        StatusLine status = response.getStatusLine();
        if (status.getStatusCode() == HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE) {
            //already finished
            if (!Thread.currentThread().isInterrupted())
                sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), null);
        } else if (status.getStatusCode() >= 300) {
            if (!Thread.currentThread().isInterrupted())
                sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), null, new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()));
        } else {
            if (!Thread.currentThread().isInterrupted()) {
                Header header = response.getFirstHeader(AsyncHttpClient.HEADER_CONTENT_RANGE);
                if (header == null) {
                    append = false;
                    current = 0;
                } else {
                    Log.v(LOG_TAG, AsyncHttpClient.HEADER_CONTENT_RANGE + ": " + header.getValue());
                }
                sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), getResponseData(response.getEntity()));
            }
        }
    }
}
 
开发者ID:yiwent,项目名称:Mobike,代码行数:26,代码来源:RangeFileAsyncHttpResponseHandler.java

示例8: handleServiceUnavailable

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
/**
 * Handle a 503 Service Unavailable status by processing the Retry-After
 * header.
 */
private void handleServiceUnavailable(State state, HttpResponse response) throws StopRequest {
    if (Constants.LOGVV) {
        Log.v(Constants.TAG, "got HTTP response code 503");
    }
    state.mCountRetry = true;
    Header header = response.getFirstHeader("Retry-After");
    if (header != null) {
        try {
            if (Constants.LOGVV) {
                Log.v(Constants.TAG, "Retry-After :" + header.getValue());
            }
            state.mRetryAfter = Integer.parseInt(header.getValue());
            if (state.mRetryAfter < 0) {
                state.mRetryAfter = 0;
            } else {
                if (state.mRetryAfter < Constants.MIN_RETRY_AFTER) {
                    state.mRetryAfter = Constants.MIN_RETRY_AFTER;
                } else if (state.mRetryAfter > Constants.MAX_RETRY_AFTER) {
                    state.mRetryAfter = Constants.MAX_RETRY_AFTER;
                }
                state.mRetryAfter += Helpers.sRandom.nextInt(Constants.MIN_RETRY_AFTER + 1);
                state.mRetryAfter *= 1000;
            }
        } catch (NumberFormatException ex) {
            // ignored - retryAfter stays 0 in this case.
        }
    }
    throw new StopRequest(DownloaderService.STATUS_WAITING_TO_RETRY,
            "got 503 Service Unavailable, will retry later");
}
 
开发者ID:SlotNSlot,项目名称:SlotNSlot_Android,代码行数:35,代码来源:DownloadThread.java

示例9: postAuthForCookie

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
/**
 * Posts the authentication parameters to the given uri and validates the response cookie.
 * Returns silently if successful, else throws.
 */
public void postAuthForCookie(Executor executor, String uri, NameValuePair[] authParams)
{
  try
  {
    Request request = Request.Post(uri).bodyForm(authParams);
    HttpResponse httpResponse = executor.execute(request).returnResponse();
    int statusCode = httpResponse.getStatusLine().getStatusCode();
    Header cookieHeader = null;
    String body = null;
    if (200 <= statusCode && statusCode < 400)
    {
      cookieHeader = httpResponse.getFirstHeader(HEADERNAME_SET_COOKIE);
      if (cookieHeader != null && StringUtils.isNotBlank(cookieHeader.getValue()))
      {
        body = EntityUtils.toString(httpResponse.getEntity());
        LoginResult result = gson.fromJson(body, LoginResult.class);
        if (result != null && result.isLoggedIn())
        {
          return; //success
        }
      }
    }
    throw new RuntimeException("Failed to obtain response cookie from uri " + uri + ", statusCode: " + statusCode
        + ", cookieHeader: " + cookieToString(cookieHeader) + ", body: " + body);
    //Note: if cookieStore already has valid cookie then response won't return a new cookie
  }
  catch (IOException e)
  {
    throw new RuntimeException("POST uri: " + uri + ", authParams", e);
  }
}
 
开发者ID:Nike-Inc,项目名称:bluegreen-manager,代码行数:36,代码来源:HttpHelper.java

示例10: isSupportRange

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
public static boolean isSupportRange(final HttpResponse response) {
    if (response == null) return false;
    Header header = response.getFirstHeader("Accept-Ranges");
    if (header != null) {
        return "bytes".equals(header.getValue());
    }
    header = response.getFirstHeader("Content-Range");
    if (header != null) {
        String value = header.getValue();
        return value != null && value.startsWith("bytes");
    }
    return false;
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:14,代码来源:OtherUtils.java

示例11: getLocation

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
/**
 * @param httpResponse http响应
 * @return
 */
public static String getLocation(HttpResponse httpResponse) {
    Header header = httpResponse.getFirstHeader("Location");
    if (header != null) {
        return header.getValue();
    }
    return "";
}
 
开发者ID:hexiaohong-code,项目名称:LoginCrawler,代码行数:12,代码来源:LoginUtils.java

示例12: b

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
private static long b(HttpResponse httpResponse) {
    long j = 0;
    Header firstHeader = httpResponse.getFirstHeader("Cache-Control");
    if (firstHeader != null) {
        String[] split = firstHeader.getValue().split("=");
        if (split.length >= 2) {
            try {
                return a(split);
            } catch (NumberFormatException e) {
            }
        }
    }
    firstHeader = httpResponse.getFirstHeader("Expires");
    return firstHeader != null ? b.b(firstHeader.getValue()) - System.currentTimeMillis() : j;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:16,代码来源:q.java

示例13: handleRedirect

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
/**
 * Handle a 3xx redirect status.
 */
private void handleRedirect(State state, HttpResponse response, int statusCode)
        throws StopRequest, RetryDownload {
    if (Constants.LOGVV) {
        Log.v(Constants.TAG, "got HTTP redirect " + statusCode);
    }
    if (state.mRedirectCount >= Constants.MAX_REDIRECTS) {
        throw new StopRequest(DownloaderService.STATUS_TOO_MANY_REDIRECTS, "too many redirects");
    }
    Header header = response.getFirstHeader("Location");
    if (header == null) {
        return;
    }
    if (Constants.LOGVV) {
        Log.v(Constants.TAG, "Location :" + header.getValue());
    }

    String newUri;
    try {
        newUri = new URI(mInfo.mUri).resolve(new URI(header.getValue())).toString();
    } catch (URISyntaxException ex) {
        if (Constants.LOGV) {
            Log.d(Constants.TAG, "Couldn't resolve redirect URI " + header.getValue()
                    + " for " + mInfo.mUri);
        }
        throw new StopRequest(DownloaderService.STATUS_HTTP_DATA_ERROR,
                "Couldn't resolve redirect URI");
    }
    ++state.mRedirectCount;
    state.mRequestUri = newUri;
    if (statusCode == 301 || statusCode == 303) {
        // use the new URI for all future requests (should a retry/resume be
        // necessary)
        state.mNewUri = newUri;
    }
    throw new RetryDownload();
}
 
开发者ID:SlotNSlot,项目名称:SlotNSlot_Android,代码行数:40,代码来源:DownloadThread.java

示例14: getEtag

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
private static String getEtag(HttpResponse response) {
    Header etagHeader = response.getFirstHeader(HttpHeaders.ETAG);
    return etagHeader == null ? null : etagHeader.getValue();
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:5,代码来源:HttpResponseResource.java

示例15: doInitialConnection

import org.apache.http.HttpResponse; //导入方法依赖的package包/类
private ConnectionInfo doInitialConnection()
        throws MessagingException {
    // For our initial connection we are sending an empty GET request to
    // the configured URL, which should be in the following form:
    // https://mail.server.com/Exchange/alias
    //
    // Possible status codes include:
    // 401 - the server uses basic authentication
    // 30x - the server is trying to redirect us to an OWA login
    // 20x - success
    //
    // The latter two indicate form-based authentication.
    ConnectionInfo info = new ConnectionInfo();

    QMailHttpClient httpClient = getHttpClient();

    HttpGeneric request = new HttpGeneric(baseUrl);
    request.setMethod("GET");

    try {
        HttpResponse response = httpClient.executeOverride(request, httpContext);
        info.statusCode = response.getStatusLine().getStatusCode();

        if (info.statusCode == 401) {
            // 401 is the "Unauthorized" status code, meaning the server wants
            // an authentication header for basic authentication.
            info.requiredAuthType = WebDavConstants.AUTH_TYPE_BASIC;
        } else if ((info.statusCode >= 200 && info.statusCode < 300) || // Success
                (info.statusCode >= 300 && info.statusCode < 400) || // Redirect
                (info.statusCode == 440)) { // Unauthorized
            // We will handle all 3 situations the same. First we take an educated
            // guess at where the authorization DLL is located. If this is this
            // doesn't work, then we'll use the redirection URL for OWA login given
            // to us by exchange. We can use this to scrape the location of the
            // authorization URL.
            info.requiredAuthType = WebDavConstants.AUTH_TYPE_FORM_BASED;

            if (formBasedAuthPath != null && !formBasedAuthPath.equals("")) {
                // The user specified their own authentication path, use that.
                info.guessedAuthUrl = getRoot() + formBasedAuthPath;
            } else {
                // Use the default path to the authentication dll.
                info.guessedAuthUrl = getRoot() + "/exchweb/bin/auth/owaauth.dll";
            }

            // Determine where the server is trying to redirect us.
            Header location = response.getFirstHeader("Location");
            if (location != null) {
                info.redirectUrl = location.getValue();
            }
        } else {
            throw new IOException("Error with code " + info.statusCode + " during request processing: " +
                    response.getStatusLine().toString());
        }
    } catch (SSLException e) {
        throw new CertificateValidationException(e.getMessage(), e);
    } catch (IOException ioe) {
        Timber.e(ioe, "IOException during initial connection");
        throw new MessagingException("IOException", ioe);
    }

    return info;
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:64,代码来源:WebDavStore.java


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