博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WebClient.UploadValues Post中文乱码的解决方法
阅读量:4486 次
发布时间:2019-06-08

本文共 1420 字,大约阅读时间需要 4 分钟。

//using (System.Net.WebClient wc = new System.Net.WebClient())

//{//    wc.Encoding = Encoding.GetEncoding("GB2312");//    NameValueCollection postData = new NameValueCollection();//    postData.Add("UserIDText", userId.ToString());//    postData.Add("UserNameText", userName);//    postData.Add("ContentText", HttpUtility.UrlEncode(content,wc.Encoding));//    postData.Add("UrlText", url);//    wc.Headers.Add(HttpRequestHeader.ContentEncoding, "gb23112");//    wc.Headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded");//    wc.UploadValues(new Uri(postUrl),"POST", postData);//}Encoding myEncoding = Encoding.GetEncoding("gb2312");string param = "UserIDText=" + HttpUtility.UrlEncode(userId.ToString(), myEncoding)    + "&" + "UserNameText=" + HttpUtility.UrlEncode(userName, myEncoding)    + "&" + "ContentText=" + HttpUtility.UrlEncode(content, myEncoding)    + "&" + "UrlText=" + HttpUtility.UrlEncode(url, myEncoding);byte[] postBytes = Encoding.ASCII.GetBytes(param);HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(postUrl);req.Method = "POST";req.ContentType = "application/x-www-form-urlencoded;charset=gb2312";req.ContentLength = postBytes.Length;using (Stream reqStream = req.GetRequestStream()){    reqStream.Write(postBytes, 0, postBytes.Length);}using (WebResponse wr = req.GetResponse()){    //在这里对接收到的页面内容进行处理}

转载于:https://www.cnblogs.com/renzaijianghu/p/4268430.html

你可能感兴趣的文章
恢复SQLServer实例连接
查看>>
Oralce 处理字符串函数
查看>>
Flex4 饼图样式(颜色渐变,点击分离,环形)
查看>>
28个Unix/Linux的命令行神器
查看>>
pb11.5破解补丁
查看>>
struts2下 数据转换器
查看>>
比特信 介绍
查看>>
ubuntu 16.04 Samba 匿名配置
查看>>
document handling
查看>>
Spring的核心容器
查看>>
Spoken English Practice(If you fail to do as I say, I will take you suffer.)
查看>>
日志分析方法
查看>>
Angular
查看>>
如何使用maven 打包源代码呢?
查看>>
python使用mysql数据库
查看>>
Linux下切换python版本
查看>>
snmptrap、snmpinform和snmptrapd的详细介绍及其用法
查看>>
JavaScript初阶(三)--------函数、闭包、立即执行函数
查看>>
linux的系统调优
查看>>
mysql之pymsql的使用
查看>>