我用HttpWebRequest发送Web请示到一个地址,其中有一个参数的内容是中文,为什么在发送的时候中文就已经变成乱码了呀?
是不是在发送之前要对中文编码?我试过urlencode,但是没有效果,高手帮帮忙啊!谢谢啊!!1
是不是在发送之前要对中文编码?我试过urlencode,但是没有效果,高手帮帮忙啊!谢谢啊!!1
解决方案 »
- 如何在time控件刷新的时候保持DIV滚动条的位置
- 请教--老上不了手呢
- 请问 HyperLink 里的 NavigateUrl 怎样调用函数?
- 有点难度:repeater嵌套 + xmlDatasource
- 问大家一个问题,在asp.net 后台代码的Timer1_Tick方法中,为什么调用 ClientScript.RegisterStartupScript(th
- 控件移除的问题,谢谢。
- iis中.htm和asp都不能执行,但.aspx是可以执行的,到底是怎么回事呢,帮个技术忙啊!
- 急,请教,一个类库和一个网站项目在同一个解决方案下。怎么在类库里访问网站项目下的web.config里的数据库链接代码。
- 请问如何在 按钮单击事件代码中 接受网页对话框的返回值?代码如下:
- 未将对象引用设置到对象的实例??
- DropDownList和TextBox控件使用
- 急!!!!!CSV问题
strParam = "http://localhost/msg/recv.asp?val=" + strMsg;
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(strParam);
//myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
myHttpWebRequest.Accept = "zh-cn";
myHttpWebRequest.ContentType = "text/html;charset=gb2312";
myHttpWebRequest.Method = "GET";
myHttpWebRequest.CookieContainer = cc;
myHttpWebRequest.Timeout = 10000;
myHttpWebRequest.CookieContainer = cc;
myHttpWebRequest.Timeout = 10000;
HttpWebResponse resp = myHttpWebRequest.GetResponse() as HttpWebResponse;
Stream s = resp.GetResponseStream();
if(s.CanRead==true)
{
StreamReader sr = new StreamReader(s,System.Text.Encoding.GetEncoding("GB2312"));
strText = sr.ReadToEnd();
sr.Close();
}
resp.Close();strText 是返回的值,这个值就是请示时发送的val参数,再次得到该值时就成为乱码,我觉得应该是在发送的时候就成乱码的,是不是要把请示做一下编码什么的?
Char[] reserved = {'?', '=', '&'};
byte[] SomeBytes = null; int i=0, j;
while(i<strMsg.Length)
{
j=strMsg.IndexOfAny(reserved, i);
if (j==-1)
{
UrlEncoded.Append(HttpUtility.UrlEncode(strMsg.Substring(i, strMsg.Length-i)));
break;
}
UrlEncoded.Append(HttpUtility.UrlEncode(strMsg.Substring(i, j-i)));
UrlEncoded.Append(strMsg.Substring(j,1));
i = j+1;
} myHttpWebRequest.ContentLength=strMsg.Length; Stream myHttpWebRequestStream=myHttpWebRequest.GetRequestStream();
StreamWriter myStreamWriter=new StreamWriter(myHttpWebRequestStream,Encoding.GetEncoding("gb2312"));
myStreamWriter.Write(strMsg);
myStreamWriter.Close();
myHttpWebRequestStream.Close();
**********************************
*本人主要使用VB+MS SQL,C#略知一二
*
*如有相关问题需要帮助
*
*可发短消息告知链接
*
*助人为快乐之本!
**********************************