当前位置:编程学习 > C#/ASP.NET >>

向webservice 发送Post请求汉字乱码问题

发送端代码如下

string postData = "<?xml version=\"1.0\" encoding = \"GB2312\"?>";
            postData += "<Data System=\"T6\" SMSType=\"01\" RegID=\"88\" RegCode=\"123456\"  MethodType=\"Send\">";
            postData += "<Row>";
            postData += "<Mobile>";
            postData += "<ID>1</ID>";
            postData += "<MobileNumber>18600029490</MobileNumber>";
            postData += "</Mobile>";
            postData += "<Content>一二三四五六</Content>";
            postData += "</Row>";
            postData += "</Data>";
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://localhost:10673/SMSWebService.asmx/GalleryInformation"); 
            req.Method = "POST"; 
            byte[] sendBuff = Encoding.Default.GetBytes(postData); 
            req.ContentLength = sendBuff.Length;
            req.ContentType = "application/x-www-form-urlencoded";
            //req.ContentType = "text/xml; charset=utf-8"; 
            StreamWriter sw = new StreamWriter(req.GetRequestStream(), Encoding.Default ); 
            sw.Write(postData);
            sw.Close(); --------------------编程问答-------------------- webservice接收

            HttpRequest httpre = System.Web.HttpContext.Current.Request;
            string XML = httpre.Form.AllKeys[0].ToString() + "=" + httpre.Form.GetValues(0).GetValue(0).ToString(); --------------------编程问答--------------------  encoding="utf-8" 试试
补充:.NET技术 ,  Web Services
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,