Winform发送POST请求到asp.net页面

 public void PostModel(string strUrl, string strParm) 
     { 
      Encoding encode = System.Text.Encoding.Default; 
    
      byte[] arrB = encode.GetBytes(strParm); 
      HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(strUrl); 
      myReq.Method = "POST" ; 
      myReq.ContentType = "application/x-www-form-urlencoded";  
      myReq.ContentLength = arrB.Length; 
      Stream outStream = myReq.GetRequestStream();       
      outStream.Write(arrB,0,arrB.Length); 
      outStream.Close(); 
      WebResponse myResp = null;  
      myResp = myReq.GetResponse(); 
      Stream ReceiveStream = myResp.GetResponseStream();         
      StreamReader readStream = new StreamReader( ReceiveStream, encode ); 
      Char[] read = new Char[256]; 
      int count = readStream.Read( read, 0, 256 ); 
      string str = null; 
      while (count > 0) 
      { 
      str += new String(read, 0, count); 
      count = readStream.Read(read, 0, 256); 
      } 
      readStream.Close(); 
      myResp.Close(); 
           
     }

  

posted on 2014-02-27 10:23  闪电光芒  阅读(139)  评论(0)    收藏  举报

导航