`
lovnet
  • 浏览: 6725757 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
文章分类
社区版块
存档分类
最新评论

Code For Posting (for post xml to another page)

阅读更多

Code For Posting

To post XML, use the following function:

Collapse Copy Code
   WebRequest req = null;
   WebResponse rsp = null;
   try
   {
    string fileName = "C:\test.xml";
    string uri = "http://localhost/PostXml/Default.aspx";
    req = WebRequest.Create(uri);
    //req.Proxy = WebProxy.GetDefaultProxy(); // Enable if using proxy
    req.Method = "POST";        // Post method
    req.ContentType = "text/xml";     // content type
    // Wrap the request stream with a text-based writer
    StreamWriter writer = new StreamWriter(req.GetRequestStream());
    // Write the XML text into the stream
    writer.WriteLine(this.GetTextFromXMLFile(fileName));
    writer.Close();
    // Send the data to the webserver
    rsp = req.GetResponse();
    
   }
   catch(WebException webEx)
   {
    
   }
   catch(Exception ex)
   {
    
   }
   finally
   {
    if(req != null) req.GetRequestStream().Close();
    if(rsp != null) rsp.GetResponseStream().Close();
   }Function to read xml data from local system
  /// <summary>
  /// Read XML data from file
  /// </summary>
  /// <param name="file"></param>
  /// <returns>returns file content in XML string format</returns>
  private string GetTextFromXMLFile(string file)
  {
   StreamReader reader = new StreamReader(file);
   string ret = reader.ReadToEnd();
   reader.Close();
   return ret;
  }

Code For Reading Posted Data

Now, on the Web server in the ASP.NET page, write the following code to access the posted data:

Collapse Copy Code
private void Page_Load(object sender, EventArgs e)
  {
     page.Response.ContentType = "text/xml";
    // Read XML posted via HTTP
    StreamReader reader = new StreamReader(page.Request.InputStream);
    String xmlData = reader.ReadToEnd(); 
}
<!-- Main Page Contents End -->

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

S Sansanwal


Member

Occupation: Architect
Location: Australia Australia
分享到:
评论

相关推荐

    Python Unit Test Automation:for Python Developers and Testers

    This knowledge is often acquired by reading source code, manuals, and posting questions on community forums, which tends to be a slow and painful process. Python Unit Test Automation will allow you ...

    Django 1.1 Testing and Debugging.pdf

    Another way to search for a matching problem report 359 Determining the release that contains a fix 363 What if a fix hasn't been released yet? 365 What if a fix hasn't been committed yet? 366 ...

    Android代码-NYBus

    NYBus is used for posting any type of event to subscribe class in Android and Java applications. NYBus also support channel to avoid the problem of event getting received at undesirable place

    WordPress 3 Search Engine Optimization.pdf

    Optimizing with the XML Sitemaps plugin for WordPress 123 SEO power tool: Google Webmaster Central 125 Summary 128 Chapter 5: Creating Optimized and Engaging Content 131 Engaging visitors with ...

    ADB and Fastboot Tools v1.4.3

    I saw another ADB installer on XDA, but it wasn't good enough for me so i'm finaly posting it here. It's very small and fast installer for tools and drivers. Features: Small - 9.18 MB Fast - 15 ...

    WordPress 2.7 Cookbook.pdf

    Displaying Adsense ads to search engines visitors only 215 Getting ready 216 How to do it 216 How it works 217 There's more... 217 Managing who Sees Ads 218 Getting ready 218 How to do it 219 ...

    Python.Unit.Test.Automation.pdf

    This knowledge is often acquired by reading source code, manuals, and posting questions on community forums, which tends to be a slow and painful process. Python Unit Test Automation will allow you ...

    Sakemail

    Thanks also to Serge Dosyukov for sending me a fix.- Also I applied another patch of Gregor Duchalski that cure a bug with PChar when this unit is used under NT. - It seems that some machines need ...

    Vue Step-by-step Guide To Mastering : Vue.js from beginner to advanced

    This book will help you to become a master of Vue JS for real This book teaches you Vue JS from beginning to advanced level Also it will show you how to install Vue JS packages step by step as well

    system mechanic Activator v1.0

    * Vista/Windows 7 users may need to use another option to terminate "ioloServiceManager" (eg. through "active task bar services window" or by using msconfig, and rebooting the computer). 05. Run...

    Efficient L2 Batch Posting Strategy on L1

    We design efficient algorithms for the batch posting of Layer 2 chain calldata on the Layer 1 chain, using tools from operations research. We relate the costs of posting and delaying, by converting ...

    WordPress Top Plugins.pdf

    Adding your gallery to a post or a page 32 Zemanta 32 CForms II 34 CForms administration 35 Modifying the default form 36 Adding your form to a page, post, or widget 36 Advanced CForms ...

    Unity.in.Action.Multiplatform.Game.Development.in.Csharp

    9.4 Posting data to a web server 217 Tracking current weather: sending post requests 218 ■ Server- side code in PHP 220 9.5 Summary 221 xii CONTENTS 10 Playing audio: sound effects and music 222 ...

    WordPress 2.8 Theme Design.pdf

    Adding You Tube video to a WordPress post 236 Summary 238 Chapter 9: Design Tips for Working with WordPress 239 The cool factor essentials 240 Backgrounds 241 Lists 242 See it in action 243 ...

    猎头系统 C# ( 人才求职招聘)

    Add job posting to their favorites list. Add frequently used searches to their favorites list. The employers can perform following operations: Register with the web site. Enter profile of their ...

    DevArt UniDAC v.3.70.0.18 (15-Jun-2011) (with Source Code)

    Bug with processing key fields on record posting is fixed Bug with empty string parameters is fixed for ASE data provider Bug with DateTime parameter is fixed for ASE data provider Bug with "SQL ...

    Senfore_DragDrop_v4.1

    Before posting to the newsgroups, I suggest you try to search for an answer on the Google (DejaNews) search engine: http://groups.google.com Chances are that your question has been asked and answered...

    Rhino5_Python_Primer.pdf

    Another very thorough resource for Python is from MIT, called "How to Think Like a Computer Scientist": http://www.greenteapress.com/thinkpython/thinkCSpy/thinkCSpy.pdf Common Exceptions/Errors: For a...

    dhtmledit.rar_LOTUS_dhtmled_dhtmledit_dhtmledit Lotus_lotus not

    Credit goes to someone at Lotus (I think) for the original code. I only extended the base code to add more features, such as cut/copy/paste and adding tables. 2. This editor is based on an Active ...

    Using Perl For Web Programming.pdf

    Returning Data to a Form for Further Revision Filling in Text Fields and Selecting List Items H Saving and Editing User-Designed Pages H G From Here G Chapter 5 Searching Searching the Full Text ...

Global site tag (gtag.js) - Google Analytics