i am using HttpClient to fetch the data from the server in Xamarin Forms using following code
public Task<HttpResponseMessage> sendData(String url,String jsonData) { using (var client = new HttpClient()) { var jsonContent = new StringContent(jsonData, System.Text.Encoding.UTF8, "application/json"); client.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite); client.BaseAddress = new Uri(baseAddress); return client.PostAsync(new Uri(url, UriKind.Relative), jsonContent); } } Here i have used Timeout.Infinite as webservice is taking around 4 mins to return the response but although i have set the Timeout.Infinite app is throwing Operation time out exception. I tried with the various timeouts as well like 240000ms but still getting operation timeout.
However, when i try to fire the same request in postman it is working but yes returning the response after 4 mins of time. As it is a third party api, we can not change anything there.
can anyone please suggest how can i forced the HttpClient to hold more for the response.
Detail exception i am getting
{System.Net.Http.HttpRequestException: An error occurred while sending the request ---> System.Net.WebException: The operation has timed out. at System.Net.HttpWebRequest+<RunWithTimeoutWorker>d__241`1[T].MoveNext () [0x000c5] in <3e9b3e26c4694baab3f689687ad40612>:0 --- End of stack trace from previous location where exception was thrown --- at System.Net.HttpWebRequest.EndGetResponse (System.IAsyncResult asyncResult) [0x00020] in <3e9b3e26c4694baab3f689687ad40612>:0 at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) [0x0000f] in <d4a23bbd2f544c30a48c44dd622ce09f>:0 --- End of stack trace from previous location where exception was thrown --- at System.Net.Http.HttpClientHandler+<SendAsync>d__64.MoveNext () [0x0041d] in <25ebe1083eaf4329b5adfdd5bbb7aa57>:0 --- End of inner exception stack trace --- at System.Net.Http.HttpClientHandler+<SendAsync>d__64.MoveNext () [0x00478] in <25ebe1083eaf4329b5adfdd5bbb7aa57>:0 --- End of stack trace from previous location where exception was thrown --- at System.Net.Http.HttpClient+<SendAsyncWorker>d__49.MoveNext () [0x000ca] in <25ebe1083eaf4329b5adfdd5bbb7aa57>:0 --- End of stack trace from previous location where exception was thrown --- at SignodeMSA.WebService.HttpService+<sendData>d__13.MoveNext () [0x0009c] in D:\VsualStudioWorkspace\SignodeMSA\SignodeMSA\SignodeMSA\WebService\HttpService.cs:141 --- End of stack trace from previous location where exception was thrown --- at SignodeMSA.WebService.RestApi+<sendDataSimple>d__96.MoveNext () [0x000b3] in D:\VsualStudioWorkspace\SignodeMSA\SignodeMSA\SignodeMSA\WebService\RestApi.cs:199 }