csharp: HttpWebRequest and HttpWebResponse_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > csharp: HttpWebRequest and HttpWebResponse

csharp: HttpWebRequest and HttpWebResponse

 2014/7/9 18:19:31  ?Geovin Du Dream Park?  程序员俱乐部  我要评论(0)
  • 摘要:http://stackoverflow.com/questions/4015324/http-request-with-postResponse.Charset="GBK";//GBK//gb2312this.CodePage=936;Session.CodePage=936;EncodingmyEncoding=Encoding.GetEncoding("GBK");byte[]data=System.Text.Encoding.GetEncoding("GBK").GetBytes
  • 标签:Web HttpWebRequest ARP HTTP

http://stackoverflow.com/questions/4015324/http-request-with-post

 

class="brush:csharp;gutter:true;"> Response.Charset = "GBK";  //GBK  //gb2312
            this.CodePage = 936;
            Session.CodePage = 936;
            Encoding myEncoding = Encoding.GetEncoding("GBK");
            byte[] data = System.Text.Encoding.GetEncoding("GBK").GetBytes("907953"); //System.Text.UnicodeEncoding.ASCII.GetBytes("135246");//UTF8
            Base64Encoder myEncoder = new Base64Encoder(data);
            StringBuilder sb = new StringBuilder();
            sb.Append(myEncoder.GetEncoded());
            string content = HttpUtility.UrlEncode("塗聚文:需要還3本書的時間為:2014-07-12:15:58,csharp", myEncoding);
            String sResult = "http://www2.lansea.com.cn/servlet/UserServiceAPI?method=sendSMS&isLongSms=0&username=87&password=232&smstype=0&mobile=13824350518&content=" + content + "";
  
            //string param = HttpUtility.UrlEncode(sResult, myEncoding);
            Response.Write(sResult);


            byte[] postBytes = Encoding.GetEncoding("GBK").GetBytes(sResult); // Encoding.GetEncoding("GBK").GetBytes(sResult);
            try
            {

                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(sResult);//sResult
                req.Method = "POST";
                req.ContentType = "application/x-www-form-urlencoded;charset=GBK";
                req.Headers["Accept-Charset"] = "GBK";
                req.Headers["Accept-Language"] = "zh-CN,zh;q=0.";
                req.AllowAutoRedirect = false;
                req.ContentLength = postBytes.Length;
                Stream webStream = req.GetRequestStream(); //发送数据 
                webStream.Write(postBytes, 0, postBytes.Length);
                webStream.Close();
                //获取返回数据
                HttpWebResponse webResponse = (HttpWebResponse)req.GetResponse();
                StreamReader reader = new StreamReader(webResponse.GetResponseStream(), Encoding.GetEncoding("GBK"));
                sResult = reader.ReadToEnd();
                sResult.Trim();
                this.TextBox1.Text = sResult;//返回是否发送成功的结果
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
                //sResult = "";
                //return sResult;
            }

 

发表评论
用户名: 匿名