Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use http-request with OkHttp 2.0 #82

Closed
rockerhieu opened this issue Jul 1, 2014 · 2 comments
Closed

How to use http-request with OkHttp 2.0 #82

rockerhieu opened this issue Jul 1, 2014 · 2 comments

Comments

@rockerhieu
Copy link

Do you have any example of setting up http-request with okhttp 2.0?

@rockerhieu
Copy link
Author

Finally I found OkUrlFactory and be able to use it to create a HttpUrlConnection:

/**
 * A {@link HttpRequest.ConnectionFactory connection factory} which uses OkHttp.
 * <p/>
 * Call {@link HttpRequest#setConnectionFactory(HttpRequest.ConnectionFactory)} with an instance of
 * this class to enable.
 */
public class OkConnectionFactory implements HttpRequest.ConnectionFactory {

  private final OkHttpClient client;

  private OkUrlFactory factory;

  public OkConnectionFactory() {
    this(new OkHttpClient());
  }

  public OkConnectionFactory(OkHttpClient client) {
    if (client == null) {
      throw new NullPointerException("Client must not be null.");
    }
    this.client = client;
    factory = new OkUrlFactory(client);
  }

  public HttpURLConnection create(URL url) throws IOException {
    return factory.open(url);
  }

  public HttpURLConnection create(URL url, Proxy proxy) throws IOException {
    throw new UnsupportedOperationException(
        "Per-connection proxy is not supported. Use OkHttpClient's setProxy instead.");
  }
}

@swankjesse
Copy link

FYI, OkUrlFactory was deprecated in December 2015 and deleted in March 2019.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants