locked
HttpClient PostAsync TimeOut, Task was canceled RRS feed

  • Question

  • User332109 posted

    i have some code:

        string data = "token=" + System.Net.WebUtility.UrlEncode(AuthService.Current.User.Token);
            data += "&areaId=" + item.ConstructionId;
            data += "&descId=" + item.DemandId;
            data += "&status=" + item.Status;
            data += "&photo=" + System.Net.WebUtility.UrlEncode(Convert.ToBase64String(photoData));
            data += "&message=" + System.Net.WebUtility.UrlEncode(item.Message);
    
           using (HttpClient client = CreateHttpClient())
            {
                using (StringContent content = new StringContent(data, Encoding.UTF8, "application/x-www-form-urlencoded"))
                {
                    using (var res = client.PostAsync("http://.../", content).Result)
                    {
                        var response = res.Content.ReadAsStringAsync().Result;
    
                        ...
                        else
                        {
                            ...
                        }
                    }
                }
            }
    

    and it works on ios, but android throw exception - task was canceled, after timeout. whats wrong?

    Friday, July 21, 2017 10:56 AM

Answers

  • User332109 posted

    this error happend when i compile on mac, but when compile on windows all right, it works.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Sunday, July 23, 2017 2:36 PM

All replies

  • User240159 posted

    Maybe INTERNET permission missing at AndroidManifest? Have you tried to use GetAsync and try to get anything from any url?

    Friday, July 21, 2017 10:59 AM
  • User332109 posted

    @NamyslawSzymaniuk said: Maybe INTERNET permission missing at AndroidManifest? Have you tried to use GetAsync and try to get anything from any url?

    yes, GetAsync works

    Friday, July 21, 2017 11:12 AM
  • User332109 posted

    this error happend when i compile on mac, but when compile on windows all right, it works.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Sunday, July 23, 2017 2:36 PM