【发布时间】:2014-10-17 17:45:46
【问题描述】:
每隔几次调用 web 服务我都会收到一个错误:com.android.volley.NoConnectionError: java.io.IOException: Hostname was not verify
仅在应用程序设置中执行“强制关闭”有助于让我的应用程序再次从 web 服务获取结果。
这是一个带有有效证书的 ssl 连接(在 iOS 上一切正常)。
我在 android 4.1.2、4.4.4 和模拟器上检查了这个。 Volley 图书馆有什么问题吗?我应该在哪里搜索以获取更多信息以解决问题。
我看到有类似的问题,但答案说要删除验证:/
@Override
protected Boolean doInBackground(Object... arg0) {
// Instantiate the cache
Cache cache = new DiskBasedCache(ctx.getCacheDir(), 1024 * 1024 * 10); // 10MB cap
// Set up the network to use HttpURLConnection as the HTTP client.
Network network = new BasicNetwork(new HurlStack());
// Instantiate the RequestQueue with the cache and network.
queue = new RequestQueue(cache, network);
queue.start();
future = RequestFuture.newFuture();
Gson gson = new Gson();
String jsonString = gson.toJson(generalAsk);
JSONObject js = null;
try {
js = new JSONObject(jsonString);
} catch (JSONException e) {
e.printStackTrace();
}
jsObjRequest = new JsonObjectRequest(Request.Method.POST, WsUtils.WS_URL + wsAddress, js, future, future);
queue.add(jsObjRequest);
try {
JSONObject response = future.get();
Gson gs = new GsonBuilder().serializeNulls().create();
generalResponse = (BaseResponse) gs.fromJson(response.toString(), c);
return true;
} catch (InterruptedException e) {
errorMessage = e.getMessage();
} catch (ExecutionException e) {
errorMessage = e.getMessage();
}
return false;
}
【问题讨论】:
-
尝试在代码的不同位置添加延迟,有时时间戳等差异会导致错误,它可能有助于调试。