78 lines
1.9 KiB
Markdown
78 lines
1.9 KiB
Markdown
# HTTPDNS Android SDK (SNI Hidden v1.0.0)
|
|
|
|
## 1. Init
|
|
|
|
```java
|
|
import com.alibaba.sdk.android.httpdns.HttpDns;
|
|
import com.alibaba.sdk.android.httpdns.HttpDnsService;
|
|
import com.alibaba.sdk.android.httpdns.InitConfig;
|
|
|
|
String appId = "app1f1ndpo9";
|
|
|
|
new InitConfig.Builder()
|
|
.setContext(context)
|
|
.setPrimaryServiceHost("httpdns-a.example.com")
|
|
.setBackupServiceHost("httpdns-b.example.com")
|
|
.setServicePort(443)
|
|
.setSecretKey("your-sign-secret") // optional if sign is enabled
|
|
.setEnableHttps(true)
|
|
.buildFor(appId);
|
|
|
|
HttpDnsService httpDnsService = HttpDns.getService(appId);
|
|
```
|
|
|
|
## 2. Resolve
|
|
|
|
```java
|
|
HTTPDNSResult result = httpDnsService.getHttpDnsResultForHostSyncNonBlocking(
|
|
"api.business.com",
|
|
RequestIpType.auto,
|
|
null,
|
|
null
|
|
);
|
|
```
|
|
|
|
## 3. Official HTTP Adapter (IP + Empty-SNI + Host)
|
|
|
|
```java
|
|
import com.alibaba.sdk.android.httpdns.network.HttpDnsAdapterOptions;
|
|
import com.alibaba.sdk.android.httpdns.network.HttpDnsAdapterRequest;
|
|
import com.alibaba.sdk.android.httpdns.network.HttpDnsAdapterResponse;
|
|
import com.alibaba.sdk.android.httpdns.network.HttpDnsHttpAdapter;
|
|
|
|
HttpDnsHttpAdapter adapter = HttpDns.buildHttpClientAdapter(
|
|
httpDnsService,
|
|
new HttpDnsAdapterOptions.Builder()
|
|
.setConnectTimeoutMillis(3000)
|
|
.setReadTimeoutMillis(5000)
|
|
.setRequestIpType(RequestIpType.auto)
|
|
.setAllowInsecureCertificatesForDebugOnly(false)
|
|
.build()
|
|
);
|
|
|
|
HttpDnsAdapterResponse response = adapter.execute(
|
|
new HttpDnsAdapterRequest("GET", "https://api.business.com/v1/ping")
|
|
);
|
|
```
|
|
|
|
Behavior is fixed:
|
|
- Resolve by `/resolve`.
|
|
- Connect to resolved IP over HTTPS.
|
|
- Keep `Host` header as business domain.
|
|
- No fallback to domain direct request.
|
|
|
|
## 4. Public Errors
|
|
|
|
- `NO_IP_AVAILABLE`
|
|
- `TLS_EMPTY_SNI_FAILED`
|
|
- `HOST_ROUTE_REJECTED`
|
|
- `RESOLVE_SIGN_INVALID`
|
|
|
|
## 5. Removed Public Params
|
|
|
|
Do not use legacy public parameters:
|
|
- `accountId`
|
|
- `serviceDomain`
|
|
- `endpoint`
|
|
- `aesSecretKey`
|