更新 NetworkUtil.java
parent
cbf7f3eeea
commit
cc0afc2338
|
|
@ -26,6 +26,8 @@ public class NetworkUtil {
|
||||||
private Handler handler = new Handler();
|
private Handler handler = new Handler();
|
||||||
private static final int MAX_RETRIES = 3;
|
private static final int MAX_RETRIES = 3;
|
||||||
private static final long RETRY_DELAY_MS = 2000; // 重试延迟,例如2秒
|
private static final long RETRY_DELAY_MS = 2000; // 重试延迟,例如2秒
|
||||||
|
// OkHttpClient的单例
|
||||||
|
private static OkHttpClient client = new OkHttpClient();
|
||||||
|
|
||||||
// API URL
|
// API URL
|
||||||
public NetworkUtil(Context context) {
|
public NetworkUtil(Context context) {
|
||||||
|
|
@ -35,6 +37,7 @@ public class NetworkUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> void postRequest(T dataObject) {
|
public <T> void postRequest(T dataObject) {
|
||||||
|
// 使用单例的OkHttpClient
|
||||||
if (dataObject instanceof CallInfo) {
|
if (dataObject instanceof CallInfo) {
|
||||||
postRequestWithRetry(dataObject, 0, callApiUrl);
|
postRequestWithRetry(dataObject, 0, callApiUrl);
|
||||||
} else if (dataObject instanceof SMSInfo) {
|
} else if (dataObject instanceof SMSInfo) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue