Ich muss Daten an den Server für alle 3 Minuten senden. Ich benutze Alarm-Manager, um alle 3 Minuten auszulösen, und ich benutze asynctask in Broadcast-Empfänger, aber ich bekomme einen Fehler als SocketTimeoutException in okhttp. Wie man das löst. Ich habe die Methode in okhttp überprüft, aber ich kann keine Methode finden mOkHttpClient.setConnectTimeout (REQ_TIMEOUT, TimeUnit.SECONDS);SocketTimeOutException bei Verwendung von okhttp Android in Broadcast-Empfänger
Hier Code
public class AlarmReceiver extends BroadcastReceiver {
private Context context;
private VALERTApplication mValertApplication;
@Override
public void onReceive(Context context, Intent intent) {
this.context=context;
new DownloadTask()
.execute();
}
private class DownloadTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
// do your request in here so that you don't interrupt the UI thread
try {
RequestBody formBody = new FormBody.Builder()
.add("userUUID", "281FDACE- 6400-4091-8BD1-F6CC2E8F64AB")
.add("readingTime", "182525")
.add("readingdate", "20160612")
.add("readingValue", "12")
.add("timezone", "EST")
.add("readingType", "9")
.build();
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("https://apps.vocare.com/api/index.cfm?endpoint=/readings")
.post(formBody)
.build();
Response response = client.newCall(request).execute();
return response.body().string();
} catch (IOException e) {
return "Unable to retrieve data. URL may be invalid.";
}
}
@Override
protected void onPostExecute(String result) {
Log.e("result",result);
}
}
}
Ich erhalte Fehler als
java.net.SocketTimeoutException: SSL handshake timed out
at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:318)
at okhttp3.internal.io.RealConnection.connectTls(RealConnection.java:239)
at okhttp3.internal.io.RealConnection.establishProtocol(RealConnection.java:196)
at okhttp3.internal.io.RealConnection.buildConnection(RealConnection.java:171)
at okhttp3.internal.io.RealConnection.connect(RealConnection.java:111)
at okhttp3.internal.http.StreamAllocation.findConnection(StreamAllocation.java:187)
at okhttp3.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:123)
at okhttp3.internal.http.StreamAllocation.newStream(StreamAllocation.java:93)
at okhttp3.internal.http.HttpEngine.connect(HttpEngine.java:296)
at okhttp3.internal.http.HttpEngine.sendRequest(HttpEngine.java:248)
at okhttp3.RealCall.getResponse(RealCall.java:243)
at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:201)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:163)
at okhttp3.RealCall.execute(RealCall.java:57)
at com.vcare.services.AlarmReceiver$DownloadTask.doInBackground(AlarmReceiver.java:76)
at com.vcare.services.AlarmReceiver$DownloadTask.doInBackground(AlarmReceiver.java:48)
at android.os.AsyncTask$2.call(AsyncTask.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
06-14 16:48:44.259 13881-13881/com.vocare E/result: Unable to retrieve data. URL may be invalid.
ist Ihr SSL-Zertifikat auf der Service-URL signiert? – SripadRaj
es ist ein SSL-Problem, überprüfen Sie Ihr Gerät hat das richtige Datum/Uhrzeit –
Wenn Sie wirklich "https://apps.cre.com/api/index.cfm?endpoint=/readings" verwenden, dann hat es offensichtlich falsche Zertifikat – Selvin