Apply post to send and receive XML files and parameters in ASP. Go

Source: Internet
Author: User
Tags urlencode

you can use post to send requests to other pages and get the results returned. You can send a post to another page from one page, or you can use HttpRequest to send a post to a page in a WinForm project. Let's take an example from an ASPX page of ASP. Post.aspx from an ASPX page, sending a request to the Receive.aspx page. 1first, build the project, add two pages, post.aspx and receive.aspx put a button in the Post page, and in its click Method we can write a piece of code like this:Private voidButton1_Click (Objectsender, System.EventArgs e) {//XML file path  stringXMLfileName = Server.MapPath ("File/frame.xml"); HttpWebRequest req=NULL; Try   {    //set the URL of the page to post to, here the Chinese parameters or have special symbols, to be encoded.    stringURL ="http://localhost/Receive.aspx"+"? Dwgfilename="+httputility.urlencode ("nnn+10111452505252706++2.bmp,nnn+10111457375757706++13.bmp")+"&pltfilename="+httputility.urlencode ("nnn+10110934363434706++ home page. JPG"); //Create a HttpWebRequest objectreq =(HttpWebRequest) httpwebrequest.create (URL); //set the way it submits data postReq. Method ="POST"; //set the value of the Content-type HTTP headerReq. ContentType ="Text/xml";//"application/x-www-form-urlencoded;charset=gb2312";       using(StreamWriter Requestwriter =NewStreamWriter (req. GetRequestStream ())) {//defines a StreamReader object that reads the contents of an XML fileStreamReader reader =NewStreamReader (XMLfileName); stringRET =Reader.     ReadToEnd (); Reader.     Close (); Requestwriter.writeline (ret);//writes the read content to the Requeststream. } Response.Write ("sent to the"); }   Catch(Exception ex) {Throwex; }   finally{     }}2. Take a look at the receive page receive.aspx the request to receive a post from the Pageload method in the Receive.aspx page. Private voidPage_Load (Objectsender, System.EventArgs e) {   if(Request.requesttype = ="POST")   {    //Response.ContentType = "Text/xml";    stringPltfilename = request.querystring["Pltfilename"];//plt file name    stringDwgfilename = request.querystring["Dwgfilename"];//DWG file Name list: 111.dwg,222.dwg,333.dwg .....//receives and reads the XML file stream from the post.StreamReader reader =NewStreamReader (Request.inputstream); String XmlData=Reader.        ReadToEnd (); Try    {     //declares a xmldoc document object, LOAD () XML stringXmlDocument doc =NewXmlDocument (); Doc.     LOADXML (XmlData); //get the XML document root nodeXmlElement root =Doc.     DocumentElement; ..... Do your own work on the XML ... }

Apply post to send and receive XML files and parameters in ASP. Go

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.