关于字符串编码的问题

yangbinhz 2003-03-27 08:47:13
在网页间传递参数常用下面的形式:http://expert.csdn.net/Expert/PostNew.asp?room=5201。。但是如果参数是汉字字符,这样保证传过去后不产生乱码?
...全文
301 30 打赏 收藏 转发到动态 举报
写回复
用AI写文章
30 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangbinhz 2003-03-28
  • 打赏
  • 举报
回复
会了,再次感谢
yangbinhz 2003-03-28
  • 打赏
  • 举报
回复
timmy3310(tim) 您解决了我的大问题,我想给你分,怎么结帖????
timmy3310 2003-03-27
  • 打赏
  • 举报
回复
你试试在IE窗口上能不能用QueryString的方式打开该页面,如果可以,那么你使用GET方式:

WebRequest req = WebRequest.Create("http://expert.csdn.net/Expert/topic/1581/1581934.jsp?mobile=13054859624,13965895647&content=内容"); //参数直接带到Url上面

req.Method = "GET";
WebResponse res = req.GetResponse();

System.Text.Encoding resEncoding = System.Text.Encoding.GetEncoding("gb2312");//接收的编码
StreamReader reader = new StreamReader( res.GetResponseStream(),resEncoding );

string html = reader.ReadToEnd(); //接收的Html

reader.Close();
res.Close();
yangbinhz 2003-03-27
  • 打赏
  • 举报
回复
timmy3310(tim) 还在吗?我还是没有处理了,用你的方法不能使对方获得参数
yangbinhz 2003-03-27
  • 打赏
  • 举报
回复
因为我不能控制接收方是如何接受,我只能传送如下的url:
http://expert.csdn.net/Expert/topic/1581/1581934.jsp?mobile=13054859624,13965895647&content=内容。
然后由对方处理。
timmy3310 2003-03-27
  • 打赏
  • 举报
回复
你说说用了我的代码出了什么错

这样应该是可以的
yangbinhz 2003-03-27
  • 打赏
  • 举报
回复
还有什么其他的方法吗?
yangbinhz 2003-03-27
  • 打赏
  • 举报
回复
都不行,晕~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
timmy3310 2003-03-27
  • 打赏
  • 举报
回复
WebRequest req = WebRequest.Create("http://expert.csdn.net/Expert/topic/1581/1581934.xml");

req.Method = "POST";

byte[] postData = System.Text.Encoding.GetEncoding("gb2312").GetBytes( "?temp=.1063959" );//Post的数据

req.ContentLength = postData.Length;
Stream postStream = req.GetRequestStream();
postStream.Write(postData, 0, postData.Length);
postStream.Close();
WebResponse res = req.GetResponse();

System.Text.Encoding resEncoding = System.Text.Encoding.GetEncoding("gb2312");//接收的编码
StreamReader reader = new StreamReader( res.GetResponseStream(),resEncoding );

string html = reader.ReadToEnd(); //接收的Html

reader.Close();
res.Close();


如果参数没有传过去,你把Method改成GET试试
yangbinhz 2003-03-27
  • 打赏
  • 举报
回复
天,!·!!急死了!感觉(timmy3310(tim) ) 的方法可行,但还是没有成功。哪个有方法快说呀,
wuzhiwen 2003-03-27
  • 打赏
  • 举报
回复
对了,关于短信,我用电脑连接手机(用的是AT指令),有一个编码之间的转换,我不知在网页上是不是也要呢?
yangbinhz 2003-03-27
  • 打赏
  • 举报
回复
给个完整的事例好吗?
yangbinhz 2003-03-27
  • 打赏
  • 举报
回复
不行呀!参数就没有传过去呀。
大健 2003-03-27
  • 打赏
  • 举报
回复
学习
timmy3310 2003-03-27
  • 打赏
  • 举报
回复
string uri = "http://www.sina.com.cn";

WebRequest req = WebRequest.Create( uri );
yangbinhz 2003-03-27
  • 打赏
  • 举报
回复
(timmy3310(tim) ) req是如何创建的,能给详细一些的信息吗?
甴曱 2003-03-27
  • 打赏
  • 举报
回复
调用中文字符集
timmy3310 2003-03-27
  • 打赏
  • 举报
回复
发送和接受的时候,指定编码:

发送:
req.Method = "POST";

byte[] postData = System.Text.Encoding.GetEncoding("gb2312").GetBytes( "?param1=aaa¶m2=bbb" );//Post的数据

req.ContentLength = postData.Length;
Stream postStream = req.GetRequestStream();
postStream.Write(postData, 0, postData.Length);
postStream.Close();

接收:
WebResponse res = req.GetResponse();

System.Text.Encoding resEncoding = System.Text.Encoding.GetEncoding("gb2312");//接收的编码
StreamReader reader = new StreamReader( res.GetResponseStream(),resEncoding );

string html = reader.ReadToEnd(); //接收的Html

reader.Close();
res.Close();
yangbinhz 2003-03-27
  • 打赏
  • 举报
回复
老兄,我就是不行呀。很急呀?哪个有好的方法呢?
lbx1979 2003-03-27
  • 打赏
  • 举报
回复
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
加载更多回复(10)

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧