Web 服务返回时如何避免 HTML 脚本
[ScriptMethod(UseHttpGet = true)]
[WebMethod]
public string sampleTest()
{
string name = "";
name = System.Web.HttpContext.Current.Request.QueryString["name"];
StringBuilder sb = new StringBuilder();
sb.Append("<message>");
sb.Append("<categoryname =" + name + "/>");
sb.Append("</message>");
return sb.ToString();
}
调用方法:
StringBuilder sb = new StringBuilder();
byte[] buf = new byte[8192];
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost/mylytica/apibridge.asmx/sampleTest?name=Shankar");
HttpWebResponse response = (HttpWebResponse)
request.GetResponse();
Stream resStream = response.GetResponseStream();
string tempString = null;
int count = 0;
do
{
count = resStream.Read(buf, 0, buf.Length);
if (count != 0)
{
tempString = Encoding.ASCII.GetString(buf, 0, count);
sb.Append(tempString);
}
}
while (count > 0);
Literal1.Text = sb.ToString();
文字值包含:
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/"><message loginstatus="OK" userid="1" /></string>
实际格式:
<message loginstatus="OK" userid="1" />
我必须做什么。
[ScriptMethod(UseHttpGet = true)]
[WebMethod]
public string sampleTest()
{
string name = "";
name = System.Web.HttpContext.Current.Request.QueryString["name"];
StringBuilder sb = new StringBuilder();
sb.Append("<message>");
sb.Append("<categoryname =" + name + "/>");
sb.Append("</message>");
return sb.ToString();
}
Invoking method :
StringBuilder sb = new StringBuilder();
byte[] buf = new byte[8192];
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost/mylytica/apibridge.asmx/sampleTest?name=Shankar");
HttpWebResponse response = (HttpWebResponse)
request.GetResponse();
Stream resStream = response.GetResponseStream();
string tempString = null;
int count = 0;
do
{
count = resStream.Read(buf, 0, buf.Length);
if (count != 0)
{
tempString = Encoding.ASCII.GetString(buf, 0, count);
sb.Append(tempString);
}
}
while (count > 0);
Literal1.Text = sb.ToString();
Literal value contains:
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/"><message loginstatus="OK" userid="1" /></string>
Actual Format:
<message loginstatus="OK" userid="1" />
What i have to do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)