Coder Social home page Coder Social logo

fullstackyang-httpclient's Introduction

fullstackyang-httpclient

重新封装的httpclient

  • 单例模式实现
private static class Holder {
    private static HttpClientInstance httpClientInstance = new HttpClientInstance();
}

public static HttpClientInstance instance() {
    return Holder.httpClientInstance;
}
  • 可自定义的失败重试
 String tryExecute(HttpRequestBase httpRequest, HttpClientContext context, Predicate<String> predicate)

tryExecute方法允许传入一个Predicate函数来自定义失败重试的条件

默认情况下,statusCode不等于200时,切换Proxy进行重试

若出现连接Proxy超时,则捕获异常,继续切换Proxy进行重试

  • 包装RequestConfig

每个传入的HttpRequest,对其Config进行重新包装

if (requestConfig != null)
    return requestConfig.getProxy() != null ? requestConfig : 
        RequestConfig.copy(requestConfig).setProxy(httpHost).build();
  • 提供代理IP

DefaultProxyProvider类提供了代理IP,可自行实现其他获取方式

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.