码迷,mamicode.com
首页 > Web开发 > 详细

ASP.net 中手工调用WS(POST方式)

时间:2015-05-01 15:56:48      阅读:106      评论:0      收藏:0      [点我收藏+]

标签:

ASP.net 中手工调用WS(POST方式)
核心代码:
string strUrl="http://localhost:21695/service1.asmx/getmythmod";
HttpWebRequest request=(HttpWebRequest)WebRequest.Create(strUrl);
request.Method="POST";
request.ContentType="application/x-www-form-url"
string paraUrlCoded+="="+HttpUtility.UrlEncode(this.txtUserId.Text);
byte[] payload;
payload=System.Text.Encodeing.UTF8.GetBytes(paraUrlCoded);
request.ContentLength=payload.Length;

Stream writer=request.GetRequestStream();
writer.Write(payload,0,payload.Length);
writer.Close();

HttpWebResponse reponse=(HttpWebResponse)request.GetResponse();
Stream s=response.GetResponseStream();
XmlTextReader Reader=ReadInnerXml();
strValue=strValue.Replace("&lt;","<");
strValue=strValue.Replace("&gt;",">");
Regex rx=new Regex(@"(\r\n)+");
strValue=rx.replace(strValue,"");
this.ClientScript.RegisterStartupScript(typeof(string),null,"alert()"+strValue+")",ture);
Reader.Close();

 

注意事项:webservice所在的web.config里面要添加:
<webServices>
<protocols>
<add name="HttpPost"/>
<add name="HttpGet"/>
</protocols>
</webServices>

 

安全风险增加

ASP.net 中手工调用WS(POST方式)

标签:

原文地址:http://www.cnblogs.com/handsome1234/p/4470732.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!