webservices处理中文参数的问题
我自己定义了一个web方法是接受中文参数并获取天气的~我现在用javascript调用此web方法时,在web方法接受此参数变成????请问该怎么解决
这是web方法
[WebMethod]
public string GetWeather(string city)
{
string weacherhtml = String.Empty;
//转换输入参数的编码类型
string mycity = System.Web.HttpUtility.UrlEncode(city, System.Text.UnicodeEncoding.GetEncoding("GB2312"));
//初始化新的 WebRequest
HttpWebRequest webrt = (HttpWebRequest)WebRequest.Create("http://php.weather.sina.com.cn/search.php?city=" + mycity);
//返回对 Internet 请求的响应。
HttpWebResponse webrs = (HttpWebResponse)webrt.GetResponse();
//从 Internet 资源返回数据流。
Stream stream = webrs.GetResponseStream();
//读取数据流
StreamReader srm = new StreamReader(stream, System.Text.Encoding.Default);
//从头读到尾,把数据读到weacherhtml中
weacherhtml = srm.ReadToEnd();
//关闭打开的资源
srm.Close();
stream.Close();
webrs.Close();
//针对不同的网站,以下开始部分和结束部分不同。
//可通过查看网站的源文件解决。
int start = weacherhtml.IndexOf("<!-- 天气状况 begin -->");
int end = weacherhtml.IndexOf("<!-- 天气状况 end -->");
//返回一个HTML的Table,预报城市天气
return weacherhtml.Substring(start, end - start);
} --------------------编程问答-------------------- 不太清除 中文序列化问题? --------------------编程问答-------------------- UrlDecode city看看是什么内容 --------------------编程问答-------------------- 试试
<configuration>
<system.web>
<globalization requestEncoding="GB2312" responseEncoding="GB2312" uiCulture="zh-CN" culture="zh-CN" fileEncoding="GB2312" />
</system.web>
</configuration>
或 改成utf-16 格式
估计是2边的 格式不对,一边是gb2312 一边还是utf-8 --------------------编程问答-------------------- http://blog.csdn.net/Knight94/archive/2006/05/01/704645.aspx 看看这个 --------------------编程问答-------------------- http://community.csdn
.net/Expert/TopicView3.asp?id=5323972
解决了 告诉一下 呵呵 --------------------编程问答-------------------- 感谢果果的提供的帮忙~但还是没有解决~我是javascript中调用的哦 ~~我把这段代码也发给大家~一起帮我看看~<script language="javascript" type="text/javascript">
var iCallID=0;
function init()
{
service.useService("http://localhost:4897/WebServices/luca.asmx?WSDL","MYPath");
var drp=document.getElementById("<%=DropDownList1.ClientID %>").value;
iCallID=service.MYPath.callService(onResult,"GetWeather",drp);
}
function onResult(result)
{
if(!result.error)
{
divResult.innerText=result.value;
}
}
</script>
补充:.NET技术 , Web Services