in the code below I am trying to get the response from a GET request to a
normal URL (or URI) but what happens is that I can only get a part of it
unless I make the current thread sleep for a certain while (in the commented
part). It seems that the Synchronous method is not synchronous since it
returned before the response is ready!!??


//-----------CODE------------------



using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;
using System.Text;

namespace TestingWebServices
{
 /// <summary>
 /// Summary description for WebForm1.
 /// </summary>
 public class WebForm1 : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.TextBox TextBox1;

  private void Page_Load(object sender, System.EventArgs e)
  {

   HttpWebRequest req = (HttpWebRequest)
WebRequest.Create("http://www.msn.com";);
   req.ContentType = "";
   req.Method = "GET";
   Stream s;
   req.Timeout = 100000;
   HttpWebResponse res = (HttpWebResponse)req.GetResponse();
   //System.Threading.Thread.Sleep(30000);
   s = res.GetResponseStream();

   StreamReader sr = new StreamReader(s, System.Text.Encoding.ASCII);
   StringBuilder sb = new StringBuilder();
   char [] data = new char[1048576];
   int nBytes;
   do
   {
    nBytes = sr.Read(data, 0, (int) 1048576);
    sb.Append(data);
   }
    while(nBytes == 1048576);
   TextBox1.Text = sb.ToString();

  }

  #region Web Form Designer generated code
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: This call is required by the ASP.NET Web Form Designer.
   //
   InitializeComponent();
   base.OnInit(e);
  }

  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  private void InitializeComponent()
  {
   this.Load += new System.EventHandler(this.Page_Load);

  }
  #endregion
 }
}

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to