Quantcast
Channel: Questions in topic: "webrequest"
Viewing all articles
Browse latest Browse all 387

multiple webrequests, one exception causes next to time out, rest are fine

$
0
0
I have a coroutine of coroutines that call tasks on webrequests. However, one will (purposefully) throw a 403 exception. The very next item will then time out when it's his turn, but all the others afterwards will work just fine, and without issue. This is really baffling to me, any insight would be appreciated. Alternatively, if there is an easier solution to getting the HEAD of a file on a remote server, that'd be nice instead. CLOSED: I found out the issue is that if the server does not close the connection, the client will not silently reopen it, trying to use the bad connection. Since the server sent an exception, it didn't close the feed and the next request tried using the same connection. After that one timed out, the connection was successfully closed and the whole thing ran as needed. I read that this is a .NET bug, but didn't go into it further as i solved my issue by setting request.KeepAlive to false. Albeit a bit slower, but speed was not essential in this process as it's all in the background for my user. paraphrased code as follows: IEnumerator Foo(){ string[] paths = {some list of paths}; foreach(string s in paths){ yield return StartCoroutine(CheckFoo(s)); { } IEnumerator CheckFoo(string s){ HttpWebRequest request = (HttpWebRequest) WebRequest.Create(s); request.Method = "HEAD"; request.KeepAlive = false; // This Fixes my issue Task task = Task.Run(() =>{ return request.GetResponse(); }); while(!task.IsCompleted) yield return null; if(task.IsFaulted || task.IsCanceled){ foreach(System.Exception e in task.Exception.InnerExceptions){ Debug.Log(imgPath + " \n " + e); } yield break; } HttpWebResponse response = task.Result as HttpWebResponse; foreach(string header in response.Headers.AllKeys){ s += "\n" + header + " > "; s += response.Headers.Get(header); } Debug.log(s); // give me all that sweet header data }

Viewing all articles
Browse latest Browse all 387

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>