title: HttpWebRequest doesn't work every time
body: <p>I'm doing a <code>WebRequest</code> to a <code>Uri</code> but the problem is that I don't get a response every time. Sometimes I need to redo it. I would like my program to check if it got no response and if so the program will automatically recall the method for the <code>WebRequest</code> until I get a response.</p>
  
  <p>In pseudocode</p>
  
  <pre><code>while(response == null)
  {
      try it again
  }
  </code></pre>
  
  <p>This is my function. The capital comment is the explanation of my issue</p>
  
  <pre><code>private string HttpWebRequest()
  {
      string xml = @"&lt;?xml version='1.0' encoding='UTF-8' standalone='yes'?&gt;
  &lt;Siri version='1.0' xmlns='http://www.siri.org.uk/'&gt;
    &lt;ServiceRequest&gt;
      &lt;RequestTimestamp&gt;2011-10-24T15:09:12Z&lt;/RequestTimestamp&gt;
      &lt;RequestorRef&gt;&lt;USERNAME&gt;&lt;/RequestorRef&gt;
      &lt;StopMonitoringRequest version='1.0'&gt;
        &lt;RequestTimestamp&gt;2011-10-24T15:09:12Z&lt;/RequestTimestamp&gt;
        &lt;MessageIdentifier&gt;12345&lt;/MessageIdentifier&gt;
        &lt;MonitoringRef&gt;020035811&lt;/MonitoringRef&gt;
      &lt;/StopMonitoringRequest&gt;
    &lt;/ServiceRequest&gt;
  &lt;/Siri&gt;";
  
      string responseFromServer = null;
  
      WebRequest request = WebRequest
      .Create("http://&lt;USERNAME&gt;:&lt;PASSWORD&gt;@nextbus.mxdata.co.uk/nextbuses/1.0/1");
  
      request.Method = "POST";
      string postData = xml;
  
      byte[] byteArray = Encoding.UTF8.GetBytes(postData);
      request.ContentType = "application/x-www-form-urlencoded";
      request.ContentLength = byteArray.Length;
      Stream dataStream = request.GetRequestStream();
      dataStream.Write(byteArray, 0, byteArray.Length);
  
      dataStream.Close();
  
  
      ////////IF I GET NO RESPONSE EVERYTHING AFTER THE NEXT LINE WILL BE IGNORED
      WebResponse response = request.GetResponse();
      ///////////THIS MESSAGEBOX WILL BE IGNORED
      MessageBox.Show(((HttpWebResponse)response).StatusDescription+" Completed");
  
  
  
      dataStream = response.GetResponseStream();
      StreamReader reader = new StreamReader(dataStream);
      responseFromServer = reader.ReadToEnd();
  
      reader.Close();
      dataStream.Close();
      response.Close();
  
      return responseFromServer;
  }
  </code></pre>
  
  <p>How can I resolve this?</p>