我正在TNS Android v5.1.0
上通过Mojave v10.14.3
和Android Studio v3.3.1
运行NativeScript-Vue应用程序(Android emulator v28.0.23
)。
我正在使用的Android仿真器(Nexus 6, API 25, Android 7.1.1 (Google APIs), x86
)无法发出HTTP请求。该请求挂起了几分钟,最终超时。我使用axios
作为HTTP客户端来使用远程C#.NET API(这是客户端的API,因此我无法直接访问它)。
我找到了SO post,并尝试了大多数解决方案。他们中的一些人似乎可以正常工作,但是几分钟后,问题再次出现。
我尝试过的解决方案:
adb kill-server
8.8.8.8
和8.8.4.4
作为DNS服务器$ANDROID_HOME/emulator/emulator -avd Nexus_6_API_25 -dns-server 8.8.8.8,8.8.4.4
其他信息:
我对移动开发还很陌生,请让我知道是否需要更多信息。
有人知道我如何解决此问题?我对物理设备的访问受到限制,因此修复此问题将提供巨大帮助。谢谢!
HTTP请求示例:
// api/config.js
import axios from "axios";
export default axios.create({
baseURL: "https://testapi.org",
headers: {
"Content-Type": "application/json",
}
});
// store/modules/auth.js
import api from "api/config.js";
const actions = {
login: async function(context, payload) {
try {
const response = await api.post("/api/account/login", payload);
context.dispatch("setUser", response.data.user);
} catch (error) {
console.log(error);
}
}
};
export default {
namespace: true,
actions
};
Logcat输出:
02-28 14:12:40.742 1722 1816 D ConnectivityService: NetworkAgentInfo [MOBILE (LTE) - 100] validation failed
02-28 14:12:48.271 2939 3095 E GoogleConversionReporter: Error sending ping
02-28 14:12:48.271 2939 3095 E GoogleConversionReporter: java.net.SocketTimeoutException: SSL handshake timed out
02-28 14:12:48.271 2939 3095 E GoogleConversionReporter: at com.google.android.gms.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
02-28 14:12:48.271 2939 3095 E GoogleConversionReporter: at com.google.android.gms.org.conscrypt.NativeSsl.doHandshake(:com.google.android.gms@13280022@13.2.80 (040700-211705629):8)
02-28 14:12:48.271 2939 3095 E GoogleConversionReporter: at com.google.android.gms.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(:com.google.android.gms@13280022@13.2.80 (040700-211705629):15)
02-28 14:12:48.271 2939 3095 E GoogleConversionReporter: at com.android.okhttp.Connection.connectTls(Connection.java:235)
02-28 14:12:48.271 2939 3095 E GoogleConversionReporter: at com.android.okhttp.Connection.connectSocket(Connection.java:199)
02-28 14:12:48.271 2939 3095 E GoogleConversionReporter: at com.android.okhttp.Connection.connect(Connection.java:172)
02-28 14:12:48.271 2939 3095 E GoogleConversionReporter: at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:367)
02-28 14:12:48.271 2939 3095 E GoogleConversionReporter: at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:130)
02-28 14:12:48.271 2939 3095 E GoogleConversionReporter: at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:329)
02-28 14:12:48.271 2939 3095 E GoogleConversionReporter: at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:246)
02-28 14:12:48.271 2939 3095 E GoogleConversionReporter: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457)
02-28 14:12:48.271 2939 3095 E GoogleConversionReporter: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:405)
02-28 14:12:48.271 2939 3095 E GoogleConversionReporter: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:521)
02-28 14:12:48.271 2939 3095 E GoogleConversionReporter: at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)
02-28 14:12:48.271 2939 3095 E GoogleConversionReporter: at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java)
02-28 14:12:48.271 2939 3095 E GoogleConversionReporter: at bsc.a(SourceFile:230)
02-28 14:12:48.271 2939 3095 E GoogleConversionReporter: at bsf.run(SourceFile:174)
02-28 14:12:48.271 2939 3095 E GoogleConversionReporter: at java.lang.Thread.run(Thread.java:761)
02-28 14:12:49.375 2651 2932 W Conscrypt: Could not set socket write timeout: java.lang.reflect.InvocationTargetException
02-28 14:12:49.376 2651 2932 W Conscrypt: at java.lang.reflect.Method.invoke(Native Method)
02-28 14:12:49.376 2651 2932 W Conscrypt: at com.google.android.gms.org.conscrypt.Platform.setSocketWriteTimeout(:com.google.android.gms@13280022@13.2.80 (040700-211705629):13)
02-28 14:12:49.376 2651 2932 W Conscrypt: Caused by: android.system.ErrnoException: setsockopt failed: EBADF (Bad file descriptor)
02-28 14:12:49.376 2651 2932 W Conscrypt: at libcore.io.Posix.setsockoptTimeval(Native Method)
02-28 14:12:49.376 2651 2932 W Conscrypt: at libcore.io.ForwardingOs.setsockoptTimeval(ForwardingOs.java:157)
02-28 14:12:50.171 2651 2930 W Conscrypt: Could not set socket write timeout: java.lang.reflect.InvocationTargetException
02-28 14:12:50.171 2651 2930 W Conscrypt: at java.lang.reflect.Method.invoke(Native Method)
02-28 14:12:50.171 2651 2930 W Conscrypt: at com.google.android.gms.org.conscrypt.Platform.setSocketWriteTimeout(:com.google.android.gms@13280022@13.2.80 (040700-211705629):13)
02-28 14:12:50.172 2651 2930 W Conscrypt: Caused by: android.system.ErrnoException: setsockopt failed: EBADF (Bad file descriptor)
02-28 14:12:50.172 2651 2930 W Conscrypt: at libcore.io.Posix.setsockoptTimeval(Native Method)
02-28 14:12:50.172 2651 2930 W Conscrypt: at libcore.io.ForwardingOs.setsockoptTimeval(ForwardingOs.java:157)
02-28 14:12:50.283 2651 2929 W Conscrypt: Could not set socket write timeout: java.lang.reflect.InvocationTargetException
02-28 14:12:50.284 2651 2929 W Conscrypt: at java.lang.reflect.Method.invoke(Native Method)
02-28 14:12:50.284 2651 2929 W Conscrypt: at com.google.android.gms.org.conscrypt.Platform.setSocketWriteTimeout(:com.google.android.gms@13280022@13.2.80 (040700-211705629):13)
02-28 14:12:50.284 2651 2929 W Conscrypt: Caused by: android.system.ErrnoException: setsockopt failed: EBADF (Bad file descriptor)
02-28 14:12:50.284 2651 2929 W Conscrypt: at libcore.io.Posix.setsockoptTimeval(Native Method)
02-28 14:12:50.284 2651 2929 W Conscrypt: at libcore.io.ForwardingOs.setsockoptTimeval(ForwardingOs.java:157)
02-28 14:12:51.482 2651 3200 W Conscrypt: Could not set socket write timeout: java.lang.reflect.InvocationTargetException
02-28 14:12:51.482 2651 3200 W Conscrypt: at java.lang.reflect.Method.invoke(Native Method)
02-28 14:12:51.482 2651 3200 W Conscrypt: at com.google.android.gms.org.conscrypt.Platform.setSocketWriteTimeout(:com.google.android.gms@13280022@13.2.80 (040700-211705629):13)
02-28 14:12:51.482 2651 3200 W Conscrypt: Caused by: android.system.ErrnoException: setsockopt failed: EBADF (Bad file descriptor)
02-28 14:12:51.482 2651 3200 W Conscrypt: at libcore.io.Posix.setsockoptTimeval(Native Method)
02-28 14:12:51.482 2651 3200 W Conscrypt: at libcore.io.ForwardingOs.setsockoptTimeval(ForwardingOs.java:157)
02-28 14:13:05.945 5154 5156 I art : Do partial code cache collection, code=30KB, data=30KB
02-28 14:13:05.946 5154 5156 I art : After code cache collection, code=30KB, data=30KB
02-28 14:13:05.946 5154 5156 I art : Increasing code cache capacity to 128KB
02-28 14:13:14.458 2363 5301 E WakeLock: GCM_HB_ALARM release without a matched acquire!