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

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>

 

安全风险增加

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。