okhttp

Make a Android application use FIPS 140-2 valiated cryptography

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 08:09:39
问题 I have client who wants our application to use FIPS 140-2 validated cryptography. The app uses Okhttp and does some HTTPS requests. AFAIK Android uses OpenSSL C library and uses java wrapper javax/net/ssl. Questions: How to make android Application FIPS 140 -2 Complaint? Is it not android at stack(OS) level should use FIPS Compliant OpenSSL, hence all app are default FIPS 140 -2 Compliant? Or our app should use FIPS 140-2 validated cryptography and make java javax/net/ssl to use it? Feasible?

OkHttp MockWebServer fails to accept connections when restarted

拟墨画扇 提交于 2019-12-10 04:21:36
问题 I'm using the OkHttp MockWebServer to mock my server responses for unit tests. It works great for the first test, but on the 2nd test my client fails with: Failed to connect to localhost/0:0:0:0:0:0:0:1:63631 This happens even if the 2nd test is exactly the same as the 1st one. Here's what I'm doing: @RunWith(RobolectricTestRunner.class) @Config(shadows = MyClassTest.MyNetworkSecurityPolicy.class, manifest = "src/main/AndroidManifest.xml", constants = BuildConfig.class, sdk = 16) public class

OkHttp support for SDK versions less than 21

泄露秘密 提交于 2019-12-10 04:04:39
问题 OkHttp has recently dropped support for Android 4, except via a separate 3.12.x branch that will be supported until end of Dec 2020 (and probably receive no more than critical updates or bugfixes). On the assumption that you wish to continue to support Android 4, like I do, since 10% of the Android user base is still a significant proportion, and don't want to be stuck in a dead-end branch... Rather than being stuck on the 3.12.x branch for all sdk versions, is there any way of using the 3.12

org.openqa.selenium.remote.internal.ApacheHttpClient is deprecated in Selenium 3.14.0 - What should be used instead?

99封情书 提交于 2019-12-10 03:04:12
问题 I am currently using Selenium 3.14.0 library in which org.openqa.selenium.remote.internal.ApacheHttpClient is deprecated with no other information. Which should be used instead? The class is already removed in the next version, 3.141.59. I am using it with EdgeDriver Service like following: final int connectionTimeout = 2 * 60 * 1000; final int socketTimeout = 10 * 60 * 1000; // 10 minute timeout final ApacheHttpClient.Factory clientFactory = new ApacheHttpClient.Factory( new

我最喜欢的 Java HTTP Client:OkHttp 基本用法

放肆的年华 提交于 2019-12-09 11:29:47
先引入依赖 Maven <dependency> <groupId>com.squareup.okhttp3</groupId> <artifactId>okhttp</artifactId> <version>3.13.1</version> </dependency> Gradle implementation('com.squareup.okhttp3:okhttp:3.13.1') 基本使用方法 创建 HTTP 客户端 OkHttpClient c = new OkHttpClient(); 构建请求 Request request = new Request.Builder() .url("https://www.google.com") .get() // get post put 等 .build(); 生成一个 Call 对象 Call call = c.newCall(request); Call 对象有两个关键的方法: execute 和 enqueue 。这两个方法中,前者同步地发送请求,直接返回 HTTP 响应;后者异步地发送请求,无返回值,通过回调返回执行结果。 同步发送请求 Response resp = null; try { Response resp = call.execute(); } catch (IOException e) { // }

Android 2019最新面试实战总结

℡╲_俬逩灬. 提交于 2019-12-09 10:24:49
Android: 今日头条屏幕适配的原理? 1:首先计算出 density,计算公式:当前设备屏幕总宽度(单位为像素)/ 设计图总宽度(单位为 dp) = densitydensity 的意思就是 1 dp 占当前设备多少像素计算density 的原因:在布局文件中填写的是什么单位,最后都会被转化为 px,系统就是通过上面的方法,将你在项目中任何地方填写的单位都转换为 px 但是,今日头条适配方案默认项目中只能以高或宽中的一个作为基准,来进行适配 简述Android中的加固和使用平台? 加固:防止代码反编译,提高代码安全性 加固三方平台,梆梆安全,360加固,爱加密等 区别:梆梆安全,360加固看不到项目中的类,爱加密看的到Java类,单看不到里面的方法实现体,效果比前面差一点点 加固的底层原理:第三方加固的应用会生成一个Apk,然后把你的APK读取出来,在封装到这个第三方应用的APK里面. 如何对APK瘦身? 1)使用混淆, 2)开启shrinkResourse(shrink-收缩),会将没有用到的图片变成一个像素点 3)删除无用的语言资源(删除国际化文件) 4)对于非透明的大图,使用JPG(没有透明度信息),代替PNG格式 5)使用tinypng进行图片压缩 6)使用webp图片格式,进一步压缩图片资源 7)使用第三方包时把用到的代码加到项目中来,避免引用整一个第三方库

java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.NETWORK

我的未来我决定 提交于 2019-12-09 06:56:45
问题 java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.NETWORK Hi i got this error while i am calling one API service from retrofit , i am searching a lot and found answer like private static void setupRestClient() { RestAdapter restAdapter = new RestAdapter.Builder() .setLogLevel(RestAdapter.LogLevel.FULL) .setEndpoint(ROOT) //.setClient(new OkClient(new com.squareup.okhttp.OkHttpClient())) //.setClient(getOkClient()) .setClient(setSSLFactoryForClient

OkHttp/Retrofit default timeout

£可爱£侵袭症+ 提交于 2019-12-08 22:43:11
问题 I was wondering how many seconds should I set to my retrofit client. How many seconds should I use as default timeout? What is the default timeout for OkHttp/Retrofit, should we let default values? 回答1: There's no a magic value and depends on expectations on your backend. If someone tells you 5s is a good value and you are having 8s average on one of your endpoints at max load times, then 8s is not working for you. As general values I've seen that below 10s is consider short and between 10s

java.io.IOException: unexpected end of stream on Connection? [duplicate]

自作多情 提交于 2019-12-08 21:44:22
问题 This question already has answers here : java.io.IOException: unexpected end of stream on Connection in android (7 answers) Closed 3 months ago . Calling one of our in-house web services seems to be giving the following error: java.io.IOException: unexpected end of stream on Connection{webservicessandbox.xxx.com:443, proxy=DIRECT@ hostAddress=174.143.185.13 cipherSuite=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA protocol=http/1.1} (recycle count=0) From what I've seen elsewhere, this is being pointed

Access raw response body in Retrofit callback

余生颓废 提交于 2019-12-08 16:55:17
问题 Retrofit version: 2.1.0 OkHttp version: 3.4.1 In the onResponse method of my Retrofit Callback implementation, I have the following logic: @Override public void onResponse(Call<BaseResponseBody<T>> call, Response<BaseResponseBody<T>> response) { if (response != null && response.isSuccessful() && response.body() != null && response.body().containsValidSuccess()) { // Perform actions using response.body().getValue(). } else { // If containsValidSuccess returns false, show a dialog that includes