【发布时间】:2017-01-10 18:27:15
【问题描述】:
我正在使用 android 4.4.2 在物理设备上进行本机 android 项目 (Java) 测试。我的 OkHttpClient websocket 连接但 10 秒后超时,这就是我试图用来更改超时设置的方法。
OkHttpClient client = new OkHttpClient();
client.setReadTimeout(0, TimeUnit.MILLISECONDS);
但它说的是Cannot resolve method setReadTimeout(int, java.util.concurrent.TimeUnit)
这些是我的导入:
import android.util.Log;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
import okhttp3.ws.WebSocket;
import okhttp3.ws.WebSocketCall;
import okhttp3.ws.WebSocketListener;
import okio.Buffer;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.TimeUnit;
在我的 gradle 文件中我有 compile 'com.squareup.okhttp3:okhttp-ws:3.4.1'
【问题讨论】: