Why do I keep getting below error when trying to use simple PostAsync()? For example, below code is used to update the user sector(s) so if the user click on first sector and wait for some seconds before clicking on the second sector then no issue but if he selects multiple one after the other without waiting it will throw this error.
Kindly help..
Here is the code:
async void update_sector(string sector)
var client = new HttpClient();
client.BaseAddress = new Uri("https://www.mydomain.com/update_user_sector.php");
var content = new FormUrlEncodedContent(new[]
new KeyValuePair<string, string>("user", Preferences.Get("UserID", null)),
new KeyValuePair<string, string>("sector", sector)
var response = await client.PostAsync("https://www.mydomain.com/update_user_sector.php", content);
and this is the error:
Java.IO.IOException: unexpected end of stream on com.android.okhttp.Address@403f40ec ---> Java.IO.EOFException: \n not found: size=0 content=...
at java.io.EOFException: \n not found: size=0 content=...
at at com.android.okhttp.okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:212)
at at com.android.okhttp.internal.http.Http1xStream.readResponse(Http1xStream.java:395)
at at com.android.okhttp.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:146)
at at com.android.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:900)
at at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:772)
at at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:493)
at at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:429)
at at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:560)
at at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:106)
at at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:30)
--- End of inner exception stack trace ---
at Java.Interop.JniEnvironment+InstanceMethods.CallIntMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0006e] in <8b3b636835d84984ba4604c1f57b1983>:0
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualInt32Method (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0002a] in <8b3b636835d84984ba4604c1f57b1983>:0
at Java.Net.HttpURLConnection.get_ResponseCode () [0x0000a] in <84ca7e914f6148f0b961431a9ac4287b>:0
at Xamarin.Android.Net.AndroidClientHandler+<>c__DisplayClass46_0.<DoProcessRequest>b__2 () [0x00000] in <84ca7e914f6148f0b961431a9ac4287b>:0
at System.Threading.Tasks.Task1[TResult].InnerInvoke () [0x0000f] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs:534 at System.Threading.Tasks.Task.Execute () [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2319 at Xamarin.Android.Net.AndroidClientHandler.DoProcessRequest (System.Net.Http.HttpRequestMessage request, Java.Net.URL javaUrl, Java.Net.HttpURLConnection httpConnection, System.Threading.CancellationToken cancellationToken, Xamarin.Android.Net.AndroidClientHandler+RequestRedirectionState redirectState) [0x00372] in <84ca7e914f6148f0b961431a9ac4287b>:0 at Xamarin.Android.Net.AndroidClientHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x002d0] in <84ca7e914f6148f0b961431a9ac4287b>:0 at System.Net.Http.HttpClient.FinishSendAsyncBuffered (System.Threading.Tasks.Task
1[TResult] sendTask, System.Net.Http.HttpRequestMessage request, System.Threading.CancellationTokenSource cts, System.Boolean disposeCts) [0x0017e] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.Net.Http/src/System/Net/Http/HttpClient.cs:506
at Angels.FirstTimeSignin.update_sector (System.String sector) [0x00110] in /Users/jassim/Projects/Angels/Angels/Angels/FirstTimeSignin.xaml.cs:211
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021
at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <84ca7e914f6148f0b961431a9ac4287b>:0
at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <84ca7e914f6148f0b961431a9ac4287b>:0
at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <84ca7e914f6148f0b961431a9ac4287b>:0
at at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.1(intptr,intptr)
at java.io.IOException: unexpected end of stream on com.android.okhttp.Address@403f40ec
at at com.android.okhttp.internal.http.Http1xStream.readResponse(Http1xStream.java:410)
at at com.android.okhttp.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:146)
at at com.android.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:900)
at at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:772)
at at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:493)
at at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:429)
at at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:560)
at at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:106)
at at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:30)
at Caused by: java.io.EOFException: \n not found: size=0 content=...
at at com.android.okhttp.okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:212)
at at com.android.okhttp.internal.http.Http1xStream.readResponse(Http1xStream.java:395)
at ... 8 more
Thanks,
Jassim
but if he selects multiple one after the other without waiting it will throw this error
Hi, JassimRahma-2616. You could disable the other buttons when clicking one button. To fix the issue, try to set android:usesCleartextTraffic
to in the <application>
tag.
Here is a similar issue case, you could refer to it.
https://stackoverflow.com/questions/54308376/how-to-fix-a-java-io-ioexception-unexpected-end-of-stream-on-connection-excep