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>

安全风险增加

上一篇:【转】启动 Eclipse 弹出“Failed to load the JNI shared library jvm.dll”错误的解决方法! .


下一篇:关于启动 Eclipse 弹出“Failed to load the JNI shared library jvm.dll”错误的解决方法!