天生舞男

我喜欢谦虚的学习各种...,希望自己能坚持一辈子,因为即使一张卫生巾也是有它的作用.
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理


                ''~``
                        ( o o )
+------------------.oooO--(_)--Oooo.---------------------+
| Li xiaojian                                            |
|                       E-mail: joblxj@163.com           |
| Fake Company          www.intechno.com                 |
| beijing, china     (   )                               |
+---------------------\ (----(   )-----------------------+
                       \_)    ) /
                             (_/
private void QueListSubmit_Click(object sender, System.EventArgs e)
  {
   divQueListData.InnerHtml = "";
   string strUser = tbxUser.Text;
   string strHost = tbxHost.Text;
   string strResult = string.Empty;
   string strPostData = "User=" + strUser + "&Host=" + strHost;
   string strdesc="";
   HttpStatusCode code = 0;

   HttpWebResponse myResponse = null;
   HttpWebRequest myRequest = null;

   try
   {
    string httpURI = tbxTestURL.Text;
    myRequest = (HttpWebRequest)WebRequest.Create(httpURI);
    myRequest.Method = "POST";
    myRequest.ContentType="application/x-www-form-urlencoded";    
    
    Encoding encoder = System.Text.Encoding.GetEncoding("utf-8");
    byte[] byteArray = encoder.GetBytes(strPostData);
    Stream myGetRequestStream = myRequest.GetRequestStream();
    myGetRequestStream.Write(byteArray, 0 , byteArray.Length);
    myGetRequestStream.Close();
    
    myResponse = (HttpWebResponse)myRequest.GetResponse();
    Stream ReceiveStream = myResponse.GetResponseStream();
    code = myResponse.StatusCode;
    strdesc = myResponse.StatusDescription;
    StreamReader sr = new StreamReader(ReceiveStream, encoder);
    Char[] read = new Char[256];
    int count = sr.Read( read, 0, 256 );
    while (count > 0)
    {
     String str = new String(read, 0, count);
     strResult += str;
     count = sr.Read(read, 0, 256);
    }
    divQueListData.InnerHtml = "<pre>"+strResult+"</pre>";
   }
   catch(WebException ex)
   {
    code = ((HttpWebResponse)ex.Response).StatusCode;
    strdesc = ((HttpWebResponse)ex.Response).StatusDescription;
   }
   divQueListData.InnerHtml += "<br>Http Status Code = " + code.ToString() + "</br>";
   divQueListData.InnerHtml += "<br>Http Status Description = "+ strdesc.ToString() +"</br>";
  }