Implementing post-send data in asp.net

Source: Internet
Author: User
Tags dotnet tostring
Asp.net| data The following code implements functionality similar to the previous XMLHTTP. The code is as follows:

Httpsenddata.aspx

<%@ Page language= "<a href=" http://dev.21tx.com/dotnet/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/dotnet/aspnet/webcontrols/"target=" _blank " >WebControls</a> "%>
<%@ Import Namespace = "System<a href=" http://dev.21tx.com/dotnet/"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);

Prepare request ...
HttpWebRequest myrequest = (HttpWebRequest) webrequest.create (strURL);
Myrequest.method = "POST";
Myrequest.contenttype= "application/x-www-form-urlencoded";
Myrequest.contentlength = data. Length;
Stream Newstream=myrequest.getrequeststream ();
Send data
Newstream.write (Data,0,data. Length);
Newstream.close ();
Response.Redirect ("httpsenddata.aspx");
}
</script>
</HEAD>
<body>
<form id= "HttpPost" method= "POST" runat= "Server" >
Title: <asp:textbox id= "TextBox1" runat= "Server" ></asp:TextBox>
<br>
Content:
<br>
<asp:textbox id= "TextBox2" runat= "Server" textmode= "MultiLine" rows= "ten" columns= "></asp:TextBox>"
<br>
<asp:button id= "Button1" runat= "Server" text= "send" ></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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.