HttpWebRequest.Method = "POST";

解决方案 »

  1.   

    我用的就是这个方法,连接服务器超时,整个程序象死掉一样
    我代码是: String data ="name=liang";
    byte[] buffer = HttpUtility.UrlEncodeToBytes(data,System.Text.Encoding.Default );

    HttpWebRequest request= (HttpWebRequest)WebRequest.Create("http://www.net.cn");
    request.Method ="POST";
    Stream s = request.GetRequestStream();
    s.Write(buffer,0,buffer.Length );
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    StreamReader reader = new StreamReader(response.GetResponseStream(),System.Text.Encoding.Default );
    this.textBox1.Text = reader.ReadToEnd();
      

  2.   

    我可以上传数据到服务企页面,我用Request.binaryRead()可以把数据读出来
    但是用request.form()读的数据确实空字符传我用get方法可以把数据发送过去,用request()也能收到,但是我用urlEncode把客户端的数据encode后,用request()又不能取到数据了
      

  3.   

    http://swxaitx.y365.com/wangye/zhuanqi/.net-1.htm
      

  4.   

    there are numerous errors in your code:1. you should not do
     HttpUtility.UrlEncodeToBytes(data,System.Text.Encoding.Default );
    you should encode the name part and value part separately, in this case, you do not need to encode2. you need to set ContentType and ContentLength3. you should close the request stream sso basically, you should do something likeString data ="name=liang";
    byte[] buffer = System.Text.Encoding.Default.GetBytes(data);HttpWebRequest request= (HttpWebRequest)WebRequest.Create("http://www.net.cn");request.Method ="POST";
    request.ContentLength = buffer.Length;
    request.ContentType = "application/x-www-form-urlencoded";Stream s = request.GetRequestStream();
    s.Write(buffer,0,buffer.Length );
    s.Close();HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    StreamReader reader = new StreamReader(response.GetResponseStream(),System.Text.Encoding.Default );
    this.textBox1.Text = reader.ReadToEnd();
    reader.Close();
    response.Close();
      

  5.   

    谢谢 思归:问题基本解决,可是如果VALUE部分是纯中文的话,我用UrlEncode(value),服务器就收不到数据。
      

  6.   

    use System.Text.Encoding.GetCoding("GB2312")
      

  7.   

    System.Windows.Forms.MessageBox.Show (System.Web.HttpUtility.UrlEncode("女",System.Text.ASCIIEncoding.GetEncoding("GB2312") )  );%c5%ae