下面的代码实现了与以前xmlhttp类似的功能。代码如下:
httpsenddata.aspx
<%@ page language="<a href="http://dev.21tx.com/do.net/csharp/" target="_blank">c#</a>"%>
<%@ import namespace = "system"%>
<%@ import namespace = "system.collections"%>
<%@ import namespace = "system.<a href="http://dev.21tx.com/web/" target="_blank">web</a>"%>
<%@ import namespace = "system.web.ui"%>
<%@ import namespace = "system.web.ui.<a href="http://dev.21tx.com/do.net/as.net/webcontrols/" target="_blank">webcontrols</a>"%>
<%@ import namespace = "system<a href="http://dev.21tx.com/do.net/" target="_blank">.net</a>"%>
<%@ import namespace = "system.io"%>
<%@ import namespace = "system.text"%>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en" >
<html>
<head>
<script runat="server">
void button1_click(object sender, system.eventargs e)
{
string strtitle = textbox1.text;
string strdesc = textbox2.text;
encoding encoding = encoding.getencoding("gb2312");
string postdata = "title=" + strtitle;
string strurl = "http://<a href="http://dev.21tx.com/web/xml/" target="_blank">xml</a>.sz.luohuedu.net/httpreceivedata.aspx";
postdata += ("&desc=" + strdesc);
byte[] data = encoding.getbytes(postdata);
// 准备请求...
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.aspx");
}
</script>
</head>
<body>
<form id="httppost" method="post" runat="server">
标题:<asp:textbox id="textbox1" runat="server"></asp:textbox>
<br>
内容:
<br>
<asp:textbox id="textbox2" runat="server" textmode="multiline" rows="10" columns="100"></asp:textbox>
<br>
<asp:button id="button1" runat="server" text=" 发 送 " onclick="button1_click"></asp:button>
</form>
</body>
</html>
httpreceivedata.aspx
<%@ page language="vb"%>
<%@ import namespace = "system" %>
<%@ import namespace = "system.web.ui" %>
<%@ import namespace = "system.web" %>
<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>
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器