• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java HttpUriRequest类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中cz.msebera.android.httpclient.client.methods.HttpUriRequest的典型用法代码示例。如果您正苦于以下问题:Java HttpUriRequest类的具体用法?Java HttpUriRequest怎么用?Java HttpUriRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



HttpUriRequest类属于cz.msebera.android.httpclient.client.methods包,在下文中一共展示了HttpUriRequest类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: sendRequest

import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
@Override
  protected RequestHandle sendRequest(DefaultHttpClient client,
                                      HttpContext httpContext, HttpUriRequest uriRequest,
                                      String contentType, ResponseHandlerInterface responseHandler,
                                      Context context) {
      if (contentType != null) {
          uriRequest.addHeader(AsyncHttpClient.HEADER_CONTENT_TYPE, contentType);
      }

      responseHandler.setUseSynchronousMode(true);

/*
       * will execute the request directly
*/
      newAsyncHttpRequest(client, httpContext, uriRequest, contentType, responseHandler, context).run();

      // Return a Request Handle that cannot be used to cancel the request
      // because it is already complete by the time this returns
      return new RequestHandle(null);
  }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:SyncHttpClient.java


示例2: getWikiResponse

import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
/**
 * Gets a standard {@link WikiResponse} object for a wiki request.  Because
 * I was getting sick of all that boilerplate.
 *
 * @param httpclient an active HTTP session
 * @param httpreq    an HTTP request (GET or POST)
 * @return a WikiResponse containing WikiResponsey stuff
 */
@NonNull
private static WikiResponse getWikiResponse(@NonNull CloseableHttpClient httpclient,
                                            @NonNull HttpUriRequest httpreq) throws Exception {
    WikiResponse toReturn = new WikiResponse();

    toReturn.document = getHttpDocument(httpclient, httpreq);

    toReturn.rootElem = toReturn.document.getDocumentElement();
    if(doesResponseHaveError(toReturn.rootElem)) {
        toReturn.hasError = true;
        toReturn.errorTextId = getErrorTextId(findErrorCode(toReturn.rootElem));
        throw new WikiException(toReturn.errorTextId);
    }

    return toReturn;
}
 
开发者ID:CaptainSpam,项目名称:geohashdroid,代码行数:25,代码来源:WikiUtils.java


示例3: process

import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
@Override
public void process(HttpResponse httpResponse, HttpContext httpContext) throws HttpException, IOException {
    if (httpResponse.getStatusLine().getStatusCode() == 302) {
        final URI reqUri = ((HttpUriRequest) httpContext.getAttribute(ExecutionContext.HTTP_REQUEST)).getURI();
        final HttpHost currentHost = (HttpHost) httpContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
        final String url = (reqUri.isAbsolute()) ? reqUri.toString() : (currentHost.toURI() + reqUri.getPath());
        final String redirect = httpResponse.getLastHeader("Location").getValue();

        String strDate = "";
        if(url.equals(Fetcher.ROOT)) {
            strDate = CommonUtils.splitDate(pattern,redirect);
            newIssueNum = CommonUtils.dateStrToLong("yyyy-MM-dd",strDate);

        }
        Log.d(SectionFragment.class.getName(),"interceptor" + redirect + ":::" + strDate + " "+ (newIssueNum >AppContext.getLatestIssueNum()));
        Log.d(SectionFragment.class.getName(),"interceptor: " + url);
    }
}
 
开发者ID:TheHandApp,项目名称:TheHand,代码行数:19,代码来源:SectionFragment.java


示例4: process

import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
@Override
public void process(HttpResponse httpResponse, HttpContext httpContext) throws HttpException, IOException {
    if (httpResponse.getStatusLine().getStatusCode() == 302) {
        final URI reqUri = ((HttpUriRequest) httpContext.getAttribute(ExecutionContext.HTTP_REQUEST)).getURI();
        final HttpHost currentHost = (HttpHost) httpContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
        final String url = (reqUri.isAbsolute()) ? reqUri.toString() : (currentHost.toURI() + reqUri.getPath());
        final String redirect = httpResponse.getLastHeader("Location").getValue();

        String pattern = "([0-9]{4}-[0-9]{2}-[0-9]{2})";
        String strDate="";
        if(url.equals(Fetcher.ROOT)) {
            strDate = CommonUtils.splitDate(pattern,redirect);
            newIssueNum = CommonUtils.dateStrToLong("yyyy-MM-dd",strDate);

        }
        Log.d("interceptor",redirect + ":::" + strDate + " "+ newIssueNum);
        Log.d("interceptor",url);
    }
}
 
开发者ID:TheHandApp,项目名称:TheHand,代码行数:20,代码来源:MainActivity.java


示例5: newAsyncHttpRequest

import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
@Override
protected AsyncHttpRequest newAsyncHttpRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, ResponseHandlerInterface responseHandler, Context context) {
    AsyncHttpRequest httpRequest = getHttpRequest(client, httpContext, uriRequest, contentType, responseHandler, context);
    return httpRequest == null
            ? super.newAsyncHttpRequest(client, httpContext, uriRequest, contentType, responseHandler, context)
            : httpRequest;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:SampleParentActivity.java


示例6: retryRequest

import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
@Override
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
    boolean retry = true;

    Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT);
    boolean sent = (b != null && b);

    if (executionCount > maxRetries) {
        // Do not retry if over max retry count
        retry = false;
    } else if (isInList(exceptionWhitelist, exception)) {
        // immediately retry if error is whitelisted
        retry = true;
    } else if (isInList(exceptionBlacklist, exception)) {
        // immediately cancel retry if the error is blacklisted
        retry = false;
    } else if (!sent) {
        // for most other errors, retry only if request hasn't been fully sent yet
        retry = true;
    }

    if (retry) {
        // resend all idempotent requests
        HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
        if (currentReq == null) {
            return false;
        }
    }

    if (retry) {
        SystemClock.sleep(retrySleepTimeMS);
    } else {
        exception.printStackTrace();
    }

    return retry;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:38,代码来源:RetryHandler.java


示例7: updateRequestHeaders

import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
public void updateRequestHeaders(HttpUriRequest uriRequest) {
    if (file.exists() && file.canWrite())
        current = file.length();
    if (current > 0) {
        append = true;
        uriRequest.setHeader("Range", "bytes=" + current + "-");
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:RangeFileAsyncHttpResponseHandler.java


示例8: getHttpDocument

import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
/**
 * Returns the content of a http request as an XML Document.  This is to be
 * used only when we know the response to a request will be XML.  Otherwise,
 * this will probably throw an exception.
 *
 * @param httpclient an active HTTP session
 * @param httpreq    an HTTP request (GET or POST)
 * @return a Document containing the contents of the response
 */
private static Document getHttpDocument(@NonNull CloseableHttpClient httpclient,
                                        @NonNull HttpUriRequest httpreq) throws Exception {
    // Remember the last request. We might want to abort it later.
    mLastRequest = httpreq;

    HttpResponse response = httpclient.execute(httpreq);

    HttpEntity entity = response.getEntity();

    return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(entity.getContent());
}
 
开发者ID:CaptainSpam,项目名称:geohashdroid,代码行数:21,代码来源:WikiUtils.java


示例9: deletePost

import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
@Override
public String deletePost(DeletePostModel model, ProgressListener listener, CancellableTask task) throws Exception {
    String url = getUsingUrl(true) + "v1/posts/" + model.postNumber;
    HttpEntity entity = ExtendedMultipartBuilder.create().setDelegates(listener, task).addString("password", model.password).build();
    HttpUriRequest request = null;
    HttpResponse response = null;
    HttpEntity responseEntity = null;
    try {
        request = RequestBuilder.delete().setUri(url).setEntity(entity).build();
        response = httpClient.execute(request);
        StatusLine status = response.getStatusLine();
        switch (status.getStatusCode()) {
            case 200:
                return null;
            case 400:
                responseEntity = response.getEntity();
                InputStream stream = IOUtils.modifyInputStream(responseEntity.getContent(), null, task);
                JSONObject json = new JSONObject(new JSONTokener(new BufferedReader(new InputStreamReader(stream))));
                throw new Exception(json.getString("message"));
            default:
                throw new Exception(status.getStatusCode() + " - " + status.getReasonPhrase());
        }
    } finally {
        try { if (request != null) request.abort(); } catch (Exception e) {}
        EntityUtils.consumeQuietly(responseEntity);
        if (response != null && response instanceof Closeable) IOUtils.closeQuietly((Closeable) response);
    }
}
 
开发者ID:miku-nyan,项目名称:Overchan-Android,代码行数:29,代码来源:HorochanModule.java


示例10: ScribeRequestAdapter

import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
public ScribeRequestAdapter(
		cz.msebera.android.httpclient.client.methods.HttpUriRequest httpUriRequest) {

	super(getMethod(httpUriRequest.getMethod()), httpUriRequest.getURI().toString());

	this.httpUriRequest = httpUriRequest;
	this.oauthParameters = new HashMap<String, String>();
}
 
开发者ID:codepath,项目名称:android-oauth-handler,代码行数:9,代码来源:ScribeRequestAdapter.java


示例11: getHttpRequest

import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
@Override
public AsyncHttpRequest getHttpRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, ResponseHandlerInterface responseHandler, Context context) {
    return null;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:5,代码来源:SampleParentActivity.java


示例12: getHttpRequest

import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
@Override
public AsyncHttpRequest getHttpRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, ResponseHandlerInterface responseHandler, Context context) {
    return new PrePostProcessRequest(client, httpContext, uriRequest, responseHandler);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:5,代码来源:PrePostProcessingSample.java


示例13: PrePostProcessRequest

import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
public PrePostProcessRequest(AbstractHttpClient client, HttpContext httpContext, HttpUriRequest request, ResponseHandlerInterface responseHandler) {
    super(client, httpContext, request, responseHandler);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:4,代码来源:PrePostProcessingSample.java


示例14: sendRequest

import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
/**
 * Puts a new request in queue as a new thread in pool to be executed
 *
 * @param client          HttpClient to be used for request, can differ in single requests
 * @param contentType     MIME body type, for POST and PUT requests, may be null
 * @param context         Context of Android application, to hold the reference of request
 * @param httpContext     HttpContext in which the request will be executed
 * @param responseHandler ResponseHandler or its subclass to put the response into
 * @param uriRequest      instance of HttpUriRequest, which means it must be of HttpDelete,
 *                        HttpPost, HttpGet, HttpPut, etc.
 * @return RequestHandle of future request process
 */
protected RequestHandle sendRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, ResponseHandlerInterface responseHandler, Context context) {
    if (uriRequest == null) {
        throw new IllegalArgumentException("HttpUriRequest must not be null");
    }

    if (responseHandler == null) {
        throw new IllegalArgumentException("ResponseHandler must not be null");
    }

    if (responseHandler.getUseSynchronousMode() && !responseHandler.getUsePoolThread()) {
        throw new IllegalArgumentException("Synchronous ResponseHandler used in AsyncHttpClient. You should create your response handler in a looper thread or use SyncHttpClient instead.");
    }

    if (contentType != null) {
        if (uriRequest instanceof HttpEntityEnclosingRequestBase && ((HttpEntityEnclosingRequestBase) uriRequest).getEntity() != null && uriRequest.containsHeader(HEADER_CONTENT_TYPE)) {
            log.w(LOG_TAG, "Passed contentType will be ignored because HttpEntity sets content type");
        } else {
            uriRequest.setHeader(HEADER_CONTENT_TYPE, contentType);
        }
    }

    responseHandler.setRequestHeaders(uriRequest.getAllHeaders());
    responseHandler.setRequestURI(uriRequest.getURI());

    AsyncHttpRequest request = newAsyncHttpRequest(client, httpContext, uriRequest, contentType, responseHandler, context);
    threadPool.submit(request);
    RequestHandle requestHandle = new RequestHandle(request);

    if (context != null) {
        List<RequestHandle> requestList;
        // Add request to request map
        synchronized (requestMap) {
            requestList = requestMap.get(context);
            if (requestList == null) {
                requestList = Collections.synchronizedList(new LinkedList<RequestHandle>());
                requestMap.put(context, requestList);
            }
        }

        requestList.add(requestHandle);

        Iterator<RequestHandle> iterator = requestList.iterator();
        while (iterator.hasNext()) {
            if (iterator.next().shouldBeGarbageCollected()) {
                iterator.remove();
            }
        }
    }

    return requestHandle;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:64,代码来源:AsyncHttpClient.java


示例15: AsyncHttpRequest

import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
public AsyncHttpRequest(AbstractHttpClient client, HttpContext context, HttpUriRequest request, ResponseHandlerInterface responseHandler) {
    this.client = Utils.notNull(client, "client");
    this.context = Utils.notNull(context, "context");
    this.request = Utils.notNull(request, "request");
    this.responseHandler = Utils.notNull(responseHandler, "responseHandler");
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:7,代码来源:AsyncHttpRequest.java


示例16: PrePostProcessRequest

import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
PrePostProcessRequest(AbstractHttpClient client, HttpContext httpContext, HttpUriRequest request, ResponseHandlerInterface responseHandler) {
    super(client, httpContext, request, responseHandler);
}
 
开发者ID:Vorlonsoft,项目名称:AndroidAsyncHTTP,代码行数:4,代码来源:PrePostProcessingSample.java


示例17: newAsyncHttpRequest

import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
@Override
protected AsyncHttpRequest newAsyncHttpRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, ResponseHandlerInterface responseHandler, Context context) {
    return new CheckNetAsyncHttpRequest(client, httpContext, uriRequest, responseHandler);
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:5,代码来源:ApiHttpClient.java


示例18: CheckNetAsyncHttpRequest

import cz.msebera.android.httpclient.client.methods.HttpUriRequest; //导入依赖的package包/类
public CheckNetAsyncHttpRequest(AbstractHttpClient client, HttpContext context, HttpUriRequest request, ResponseHandlerInterface responseHandler) {
    super(client, context, request, responseHandler);
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:4,代码来源:ApiHttpClient.java



注:本文中的cz.msebera.android.httpclient.client.methods.HttpUriRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Yaml类代码示例发布时间:2022-05-22
下一篇:
Java AutoCompletionBinding类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap