简体   繁体   中英

Timeout httpClient on windows phone 7

i have a problem about timeout in http client windows phone, i already read on microsoft forum and know about default timeout was 100 seconds. is has a way to change default timeout? i already modify my coding but it's nothing, i want to change about 4 minutes and then get timeout reques. its a sample my codding

 HttpClientHandler _handler = new HttpClientHandler();
                _handler.CookieContainer = InfosysHttpClient.COOKIE_CONTAINER;
                _handler.UseCookies = true;

                //CancellationTokenSource cts = new CancellationTokenSource(new TimeSpan(0, 0,request.Timeout, 0, 300));

                //var cts = new CancellationTokenSource();

                HttpClient _client = new HttpClient(_handler);
                //cts.CancelAfter(new TimeSpan(0, 0, request.Timeout, 0, 300));
                //_client.Timeout = Thread.Sleep((TimeSpan.FromMinutes(2)));
                //_client.Timeout = new TimeSpan(0, 0,request.Timeout, 0, 300);


                try
                {     


                    HttpResponseMessage _result = await _client.PostAsync(request.Url, _content);

                        _resp.Message = await _result.Content.ReadAsStringAsync();

                        _resp.Status = _result.StatusCode.ToString();

                }

As you've say, and as you've read, it's not possible to create an extended timeout period.

If you really need a longer timeout you'll need to make a socket connection yourself and handle the whole process yourself which will allow you to set whatever timeout you wish. Just be aware of possibly needing to forcibly hold the connection open to stop the radio timing out.
Keeping the connection open longer for a possible response can have a negative impact on resource and battery use so make sure you have fully understood and considered all the implications of what you're trying to achieve.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM