Implement post data sending in ASP. NET

Source: Internet
Author: User

Httpsenddata. aspx

<% @ Page Language = "C #" %>
<% @ Import namespace = "system" %>
<% @ Import namespace = "system. Collections" %>
<% @ Import namespace = "system. Web" %>
<% @ Import namespace = "system. Web. UI" %>
<% @ Import namespace = "system. Web. UI. webcontrols" %>
<% @ Import namespace = "system. Net" %>
<% @ Import namespace = "system. Io" %>
<% @ Import namespace = "system. Text" %>

<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<SCRIPT runat = "server">
Void button#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://xml.sz.luohuedu.net/HttpReceiveData.aspx ";
Postdata + = ("& DESC =" + strdesc );
Byte [] DATA = encoding. getbytes (postdata );

// Prepare the 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 = "10" columns = "100"> </ASP: textbox>
<Br>
<Asp: button id = "button1" runat = "server" text = "sending" onclick = "button#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>

 

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.