Why does a web request times out the second time?

+3 votes
asked Aug 5, 2016 in Programming by Andy Mount Student (280 points)
edited Aug 5, 2016 by Andy Mount

Im using HttpWebRequest in Unity 5.3. Everything works as expected, for the first time at least. Every second attempt freezes the Unity editor. Why is this working only once?

Here is my code:

StreamWriter writer = new StreamWriter(request.GetRequestStream());
writer.Write(data.ToString());
writer.Flush();
writer.Close();

HttpWebResponse response = request.GetResponse() as HttpWebResponse;

StreamReader responseStream = new StreamReader(response.GetResponseStream(), enc);

responseData = responseStream.ReadToEnd();
response.Close();
responseStream.Close();

1 Answer

0 votes
answered Aug 5, 2016 by Bugstacker Senior (4,800 points)
Use a smaller timeout and reconnect.
Welcome to Bugstacker Q&A, where you can ask questions concerning Game Development, Programming and Design and receive answers from other members of the community.

Help for

...