欢迎光临
我们一直在努力

在ASP.NET中实现POST发送数据-.NET教程,Asp.Net开发

建站超值云服务器,限时71元/月

下面的代码实现了与以前xmlhttp类似的功能。代码如下:

httpsenddata.aspx

<%@ page language="c#"%><br /> <%@ import namespace = "system"%><br /> <%@ import namespace = "system.collections"%><br /> <%@ import namespace = "system.web"%><br /> <%@ import namespace = "system.web.ui"%><br /> <%@ import namespace = "system.web.ui.webcontrols"%><br /> <%@ import namespace = "system.net"%><br /> <%@ import namespace = "system.io"%><br /> <%@ import namespace = "system.text"%></p> <p><!doctype html public "-//w3c//dtd html 4.0 transitional//en" ><br /> <html><br /> <head><br /> <script runat="server"> void button1_click(object sender, system.eventargs e) { string strtitle = textbox1.text; string strdesc = textbox2.text;</p> <p> encoding encoding = encoding.getencoding("gb2312");</p> <p> string postdata = "title=" + strtitle; string strurl = "http://xml.sz.luohuedu.net/httpreceivedata.<a href="http://www.west999.com/www/go/?url=http://www.chinaitpower.com/dev/web/asp/index.html" target="_blank" rel="nofollow" >asp</a>x"; postdata += ("&desc=" + strdesc); byte[] data = encoding.getbytes(postdata);</p> <p> // 准备请求... httpwebrequest myrequest = (httpwebrequest)webrequest.create(strurl); myrequest.method = "post"; myrequest.contenttype="application/x-www-form-urlencoded"; myrequest.contentlength = data.length; stream newstream=myrequest.getrequeststream(); // 发送数据 newstream.write(data,0,data.length); newstream.close(); response.redirect("httpsenddata.<a href="http://www.west999.com/www/go/?url=http://www.chinaitpower.com/dev/web/asp/index.html" target="_blank" rel="nofollow" >asp</a>x"); } </script><br /> </head><br /> <body></p> <form id="httppost" method="post" runat="server"> 标题:<<a href="http://www.west999.com/www/go/?url=http://www.chinaitpower.com/dev/web/asp/index.html" target="_blank" rel="nofollow" >asp</a>:textbox id=&#8221;textbox1&#8243; runat=&#8221;server&#8221;></<a href="http://www.west999.com/www/go/?url=http://www.chinaitpower.com/dev/web/asp/index.html" target="_blank" rel="nofollow" >asp</a>:textbox><br /> <br /> 内容:<br /> <br /> <<a href="http://www.west999.com/www/go/?url=http://www.chinaitpower.com/dev/web/asp/index.html" target="_blank" rel="nofollow" >asp</a>:textbox id=&#8221;textbox2&#8243; runat=&#8221;server&#8221; textmode=&#8221;multiline&#8221; rows=&#8221;10&#8243; columns=&#8221;100&#8243;></<a href="http://www.west999.com/www/go/?url=http://www.chinaitpower.com/dev/web/asp/index.html" target="_blank" rel="nofollow" >asp</a>:textbox><br /> <br /> <<a href="http://www.west999.com/www/go/?url=http://www.chinaitpower.com/dev/web/asp/index.html" target="_blank" rel="nofollow" >asp</a>:button id=&#8221;button1&#8243; runat=&#8221;server&#8221; text=&#8221; 发 送 &#8221; onclick=&#8221;button1_click&#8221;></<a href="http://www.west999.com/www/go/?url=http://www.chinaitpower.com/dev/web/asp/index.html" target="_blank" rel="nofollow" >asp</a>:button><br /> </form> <p></body><br /> </html><br />

httpreceivedata.aspx

<%@ page language="vb"%><br /> <%@ import namespace = "system" %><br /> <%@ import namespace = "system.web.ui" %><br /> <%@ import namespace = "system.web" %><br /> <script runat="server"> sub page_load(byval sender as system.object, byval e as system.eventargs) if request.servervariables("request_method").tostring() = "post" then dim connstr as string connstr = "provider=microsoft.jet.oledb.4.0;data source=" + server.mappath("test.mdb") dim cn as new system.data.oledb.oledbconnection(connstr) dim strsql as string = "insert into testtable (title,description) values(" _ + request.form("title").tostring() + "," + request.form("desc").tostring() + ")" cn.open() dim cmd as new system.data.oledb.oledbcommand(strsql, cn) cmd.executenonquery() cn.close() cn.dispose() cmd.dispose() end if end sub </script><br />

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 在ASP.NET中实现POST发送数据-.NET教程,Asp.Net开发
分享到: 更多 (0)