我正在开发android本机woocomerce应用程序,我所面临的问题是,当我在Android4.x版本上构建和生成apk并运行时,它不会从api中获取数据,只是显示了协议引起的一个SSL错误:附在下面的 在这里输入图像描述版本4.xi.e 5之上,或者在工作中很好地获取所有数据。
我试过TLS转换,但没有完全成功。
package com.app.androidwoocommerce.network;
import com.app.androidwoocommerce.constant.ConstantValues;
import com.app.androidwoocommerce.oauth.BasicOAuth;
import com.app.androidwoocommerce.oauth.OAuthInterceptor;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
/**
* APIClient handles all the Network API Requests using Retrofit Library
**/
public class APIClient {
public static Retrofit retrofit;
private static APIRequests apiRequests;
private static final String BASE_URL = ConstantValues.WOOCOMMERCE_URL;
// Singleton Instance of APIRequests
public static APIRequests getInstance() {
if (apiRequests == null) {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OAuthInterceptor oauth1Woocommerce = new OAuthInterceptor.Builder()
.consumerKey(ConstantValues.WOOCOMMERCE_CONSUMER_KEY)
.consumerSecret(ConstantValues.WOOCOMMERCE_CONSUMER_SECRET)
.build();
BasicOAuth basicOAuthWoocommerce = new BasicOAuth.Builder()
.consumerKey(ConstantValues.WOOCOMMERCE_CONSUMER_KEY)
.consumerSecret(ConstantValues.WOOCOMMERCE_CONSUMER_SECRET)
.build();
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addInterceptor(interceptor)
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.addInterceptor(BASE_URL.startsWith("http://")? oauth1Woocommerce : basicOAuthWoocommerce)
.build();
/* OkHttpClient okHttpClient = new OkHttpClient().newBuilder()
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.addInterceptor(BASE_URL.startsWith("http://")? oauth1Woocommerce : basicOAuthWoocommerce)
.addInterceptor(interceptor)
.build();*/
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.build();
apiRequests = retrofit.create(APIRequests.class);
return apiRequests;
}
else {
return apiRequests;
}
}
}我希望API连接到设备4.x,在其他版本中也是如此,min已经被检查过了,它有某种ssl或tls问题,我认为
发布于 2019-02-13 13:34:37
代码不是由我编写的,但是我在我的项目中得到了它,我可以确认它是有效的。
fun Context.installTls12() {
// important code starts here
try {
ProviderInstaller.installIfNeeded(this)
} catch (e: GooglePlayServicesRepairableException) {
// Prompt the user to install/update/enable Google Play services.
GoogleApiAvailability.getInstance().showErrorNotification(this, e.connectionStatusCode)
} catch (e: GooglePlayServicesNotAvailableException) {
// Indicates a non-recoverable error: let the user know.
}
}Java版本应该看起来非常类似。早点打电话。Kotlin扩展并不是必需的,但是它非常有用。
https://stackoverflow.com/questions/54671425
复制相似问题