I have two domain pointing to the same server, one have ipv6 enabled, the other one doesn't.
4 scenario for sending request
- ipv6 enabled, using wifi, return in about 4sec
- ipv6 enabled, using cellular data, return in about 36SEC
- ipv6 disabled, using wifi, return in about 4sec
- ipv6 disabled, using cellular data, return in about 6sec
Below is my java code, hopefully someone can help me with the ipv6 enabled, using cellular data situation..
protected int executePost(String _url, byte[] _data) {
OkHttpClient bootstrapClient = new OkHttpClient.Builder()
.callTimeout(20, TimeUnit.SECONDS)
.cache(new Cache(new File("/local/cacheDirectory"), 10 * 1024 * 1024))
.retryOnConnectionFailure(false)
.followRedirects(false)
.followSslRedirects(false)
.build();
Dns dns = new DnsOverHttps.Builder().client(bootstrapClient)
.url(HttpUrl.get("https://cloudflare-dns.com/dns-query"))
.bootstrapDnsHosts(getByIp("1.1.1.1"), getByIp("1.0.0.1"))
.includeIPv6(true)
.post(true)
.build();
OkHttpClient client = bootstrapClient.newBuilder().dns(dns).build();
final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
RequestBody postBody = RequestBody.create(_data, JSON);
Request post = new Request.Builder()
.url(_url)
.post(postBody)
.addHeader("Content-Type", "application/json")
.build();
try (Response response = client.newCall(post).execute()) {
m_httpStatus = response.code();
m_httpBody = response.body().string();
} catch(Exception e) {
m_httpStatus = -1;
m_httpError = e.getCause().toString();
}
return m_httpStatus;
}
p.s. I'm using okhttp:5.0.0-alpha.11, and I am sure my device have ipv6.