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


Java HttpResponse.getStatusLine方法代码示例

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


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

示例1: handleResponse

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
/**
 * Returns the response body as a String if the response was successful (a
 * 2xx status code). If no response body exists, this returns null. If the
 * response was unsuccessful (>= 300 status code), throws an
 * {@link HttpResponseException}.
 */
public String handleResponse(final HttpResponse response)
        throws HttpResponseException, IOException {
    final StatusLine statusLine = response.getStatusLine();
    final HttpEntity entity = response.getEntity();
    if (statusLine.getStatusCode() >= 300) {
        EntityUtils.consume(entity);
        throw new HttpResponseException(statusLine.getStatusCode(),
                statusLine.getReasonPhrase());
    }
    return entity == null ? null : EntityUtils.toString(entity);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:18,代码来源:BasicResponseHandler.java

示例2: handleResponse

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
public Multistatus handleResponse(HttpResponse response) throws SardineException, IOException
	{
		super.validateResponse(response);

		// Process the response from the server.
		HttpEntity entity = response.getEntity();
		StatusLine statusLine = response.getStatusLine();
		if (entity == null)
		{
			throw new SardineException("No entity found in response", statusLine.getStatusCode(),
					statusLine.getReasonPhrase());
		}
		
//		boolean debug=false;
//		//starn: for debug purpose, display the stream on the console
//		if (debug){
//			String result = convertStreamToString(entity.getContent());
//			System.out.println(result);
//			InputStream in = new ByteArrayInputStream(result.getBytes()); 
//			return this.getMultistatus(in);
//		}
//		else {
//			return this.getMultistatus(entity.getContent());
//		}
		Multistatus m = new Multistatus();
		new XmlMapper(entity.getContent(),m);
		return m;
	}
 
开发者ID:starn,项目名称:encdroidMC,代码行数:29,代码来源:MultiStatusResponseHandler.java

示例3: validateResponse

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
/**
 * Checks the response for a statuscode between {@link HttpStatus#SC_OK} and {@link HttpStatus#SC_MULTIPLE_CHOICES}
 * and throws an {@link de.aflx.sardine.impl.SardineException} otherwise.
 *
 * @param response to check
 * @throws SardineException when the status code is not acceptable.
 */
protected void validateResponse(HttpResponse response) throws SardineException
{
	StatusLine statusLine = response.getStatusLine();
	int statusCode = statusLine.getStatusCode();
	if (statusCode >= HttpStatus.SC_OK && statusCode < HttpStatus.SC_MULTIPLE_CHOICES)
	{
		return;
	}
	throw new SardineException("Unexpected response", statusLine.getStatusCode(), statusLine.getReasonPhrase());
}
 
开发者ID:starn,项目名称:encdroidMC,代码行数:18,代码来源:ValidatingResponseHandler.java

示例4: handleResponse

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
public String handleResponse(HttpResponse response) throws IOException
{
	super.validateResponse(response);

	// Process the response from the server.
	HttpEntity entity = response.getEntity();
	if (entity == null)
	{
		StatusLine statusLine = response.getStatusLine();
		throw new SardineException("No entity found in response", statusLine.getStatusCode(),
				statusLine.getReasonPhrase());
	}
	return this.getToken(entity.getContent());
}
 
开发者ID:starn,项目名称:encdroidMC,代码行数:15,代码来源:LockResponseHandler.java

示例5: handleResponse

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
public Boolean handleResponse(HttpResponse response) throws SardineException
{
	StatusLine statusLine = response.getStatusLine();
	int statusCode = statusLine.getStatusCode();
	if (statusCode < HttpStatus.SC_MULTIPLE_CHOICES)
	{
		return true;
	}
	if (statusCode == HttpStatus.SC_NOT_FOUND)
	{
		return false;
	}
	throw new SardineException("Unexpected response", statusCode, statusLine.getReasonPhrase());
}
 
开发者ID:starn,项目名称:encdroidMC,代码行数:15,代码来源:ExistsResponseHandler.java

示例6: doSendRequest

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
/**
 * Send the given request over the given connection.
 * <p>
 * This method also handles the expect-continue handshake if necessary.
 * If it does not have to handle an expect-continue handshake, it will
 * not use the connection for reading or anything else that depends on
 * data coming in over the connection.
 *
 * @param request   the request to send, already
 *                  {@link #preProcess preprocessed}
 * @param conn      the connection over which to send the request,
 *                  already established
 * @param context   the context for sending the request
 *
 * @return  a terminal response received as part of an expect-continue
 *          handshake, or
 *          <code>null</code> if the expect-continue handshake is not used
 *
 * @throws IOException in case of an I/O error.
 * @throws HttpException in case of HTTP protocol violation or a processing
 *   problem.
 */
protected HttpResponse doSendRequest(
        final HttpRequest request,
        final HttpClientConnection conn,
        final HttpContext context) throws IOException, HttpException {
    Args.notNull(request, "HTTP request");
    Args.notNull(conn, "Client connection");
    Args.notNull(context, "HTTP context");

    HttpResponse response = null;

    context.setAttribute(HttpCoreContext.HTTP_CONNECTION, conn);
    context.setAttribute(HttpCoreContext.HTTP_REQ_SENT, Boolean.FALSE);

    conn.sendRequestHeader(request);
    if (request instanceof HttpEntityEnclosingRequest) {
        // Check for expect-continue handshake. We have to flush the
        // headers and wait for an 100-continue response to handle it.
        // If we get a different response, we must not send the entity.
        boolean sendentity = true;
        final ProtocolVersion ver =
            request.getRequestLine().getProtocolVersion();
        if (((HttpEntityEnclosingRequest) request).expectContinue() &&
            !ver.lessEquals(HttpVersion.HTTP_1_0)) {

            conn.flush();
            // As suggested by RFC 2616 section 8.2.3, we don't wait for a
            // 100-continue response forever. On timeout, send the entity.
            if (conn.isResponseAvailable(this.waitForContinue)) {
                response = conn.receiveResponseHeader();
                if (canResponseHaveBody(request, response)) {
                    conn.receiveResponseEntity(response);
                }
                final int status = response.getStatusLine().getStatusCode();
                if (status < 200) {
                    if (status != HttpStatus.SC_CONTINUE) {
                        throw new ProtocolException(
                                "Unexpected response: " + response.getStatusLine());
                    }
                    // discard 100-continue
                    response = null;
                } else {
                    sendentity = false;
                }
            }
        }
        if (sendentity) {
            conn.sendRequestEntity((HttpEntityEnclosingRequest) request);
        }
    }
    conn.flush();
    context.setAttribute(HttpCoreContext.HTTP_REQ_SENT, Boolean.TRUE);
    return response;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:76,代码来源:HttpRequestExecutor.java

示例7: getLocationURI

import ch.boye.httpclientandroidlib.HttpResponse; //导入方法依赖的package包/类
public URI getLocationURI(
        final HttpRequest request,
        final HttpResponse response,
        final HttpContext context) throws ProtocolException {
    Args.notNull(request, "HTTP request");
    Args.notNull(response, "HTTP response");
    Args.notNull(context, "HTTP context");

    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    //get the location header to find out where to redirect to
    final Header locationHeader = response.getFirstHeader("location");
    if (locationHeader == null) {
        // got a redirect response, but no location header
        throw new ProtocolException(
                "Received redirect response " + response.getStatusLine()
                + " but no location header");
    }
    final String location = locationHeader.getValue();
    if (this.log.isDebugEnabled()) {
        this.log.debug("Redirect requested to location '" + location + "'");
    }

    final RequestConfig config = clientContext.getRequestConfig();

    URI uri = createLocationURI(location);

    // rfc2616 demands the location value be a complete URI
    // Location       = "Location" ":" absoluteURI
    try {
        if (!uri.isAbsolute()) {
            if (!config.isRelativeRedirectsAllowed()) {
                throw new ProtocolException("Relative redirect location '"
                        + uri + "' not allowed");
            }
            // Adjust location URI
            final HttpHost target = clientContext.getTargetHost();
            Asserts.notNull(target, "Target host");
            final URI requestURI = new URI(request.getRequestLine().getUri());
            final URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, target, false);
            uri = URIUtils.resolve(absoluteRequestURI, uri);
        }
    } catch (final URISyntaxException ex) {
        throw new ProtocolException(ex.getMessage(), ex);
    }

    RedirectLocations redirectLocations = (RedirectLocations) clientContext.getAttribute(
            HttpClientContext.REDIRECT_LOCATIONS);
    if (redirectLocations == null) {
        redirectLocations = new RedirectLocations();
        context.setAttribute(HttpClientContext.REDIRECT_LOCATIONS, redirectLocations);
    }
    if (!config.isCircularRedirectsAllowed()) {
        if (redirectLocations.contains(uri)) {
            throw new CircularRedirectException("Circular redirect to '" + uri + "'");
        }
    }
    redirectLocations.add(uri);
    return uri;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:61,代码来源:DefaultRedirectStrategy.java


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