在我的android应用中: app / build.gradle
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 18
targetSdkVersion 28
versionCode 427
versionName "2.1.427"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
dependencies {
annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
annotationProcessor "org.androidannotations:ormlite:$AAVersion"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:animated-vector-drawable:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:customtabs:28.0.0'
implementation 'com.android.support:exifinterface:28.0.0'
implementation 'com.android.support:support-media-compat:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.7'
implementation 'com.google.android.gms:play-services-gcm:16.0.0'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.j256.ormlite:ormlite-android:5.1'
implementation 'commons-codec:commons-codec:1.11'
implementation 'commons-io:commons-io:2.6'
implementation 'org.apache.commons:commons-lang3:3.8.1'
implementation 'org.apache.httpcomponents:httpclient:4.3.6'
implementation "org.androidannotations:androidannotations-api:$AAVersion"
implementation "org.androidannotations:ormlite-api:$AAVersion"
implementation project(':fab')
implementation project(':fointeraction')
implementation project(':scanlib')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
}
我使用“ org.apache.http ”创建http请求。
当我在Android 6.0上启动我的应用程序时,它就成功开始了。 我成功创建http请求,成功获得http响应。 很好。
url = https://some_host/
但是,当我在Android 9.0上启动ap时,我成功创建了http请求,但未返回http响应。这里有错误:
Class 'org.apache.http.conn.ssl.SSLSocketFactory' does not implement interface 'org.apache.http.conn.scheme.SchemeSocketFactory' in call to 'java.net.Socket org.apache.http.conn.scheme.SchemeSocketFactory.createSocket(org.apache.http.params.HttpParams)' (declaration of 'org.apache.http.impl.conn.DefaultClientConnectionOperator' appears in /data/app/com.myproject.app-fa20LoyoX_ze9Vk1tE46kg==/split_lib_dependencies_apk.apk)
java.lang.IncompatibleClassChangeError: Class 'org.apache.http.conn.ssl.SSLSocketFactory' does not implement interface 'org.apache.http.conn.scheme.SchemeSocketFactory' in call to 'java.net.Socket org.apache.http.conn.scheme.SchemeSocketFactory.createSocket(org.apache.http.params.HttpParams)' (declaration of 'org.apache.http.impl.conn.DefaultClientConnectionOperator' appears in /data/app/com.myproject.app-fa20LoyoX_ze9Vk1tE46kg==/split_lib_dependencies_apk.apk)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:165)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
at com.myproject.app.transport.lite.FOServiceLite.executeRequestLow(FOServiceLite.java:322)
at com.myproject.app.transport.lite.FOServiceLite.loadApplicationProfileResponse(FOServiceLite.java:479)
at com.myproject.app.transport.lite.FOServiceLite.executeCommand(FOServiceLite.java:494)
at com.myproject.app.transport.lite.FOServiceLite.executeCommand(FOServiceLite.java:679)
at com.myproject.app.service.ProviderService.sync(ProviderService.java:53)
at com.myproject.app.fragment.SubscribesFragment.loadProviders(SubscribesFragment.java:73)
at com.myproject.app.fragment.SubscribesFragment_.access$1801(SubscribesFragment_.java:23)
at com.myproject.app.fragment.SubscribesFragment_$19.execute(SubscribesFragment_.java:291)
at org.androidannotations.api.BackgroundExecutor$Task.run(BackgroundExecutor.java:405)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:459)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
以下是Java代码段:
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
HttpPost post = new HttpPost(url.toString());
post.setEntity(be);
be = null;
// Reporting purpose
requestStartDate = new Date();
HttpResponse httpResponse = client.execute(post);
post = null;
StatusLine statusLine = httpResponse.getStatusLine();
此行中的错误:
HttpResponse httpResponse = client.execute(post);
答案 0 :(得分:1)
我遇到了同样的问题并提出了这个问题:
client.getConnectionManager().getSchemeRegistry().register( new Scheme("https", SSLSocketFactory.getSocketFactory(), 443) );
在 client.execute(post) 行之上确实解决了我的问题。
(来源:@Mandeep Singh 在原始帖子的评论中)