Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6050125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:39:14+00:00 2026-05-23T07:39:14+00:00

I have a controller that looks like this for importing xml to my site:

  • 0

I have a controller that looks like this for importing xml to my site:

    [HttpPost]
    public ActionResult Import(string xml)
    {

I have a standalone application that reads an xml file and sends it to the url. It looks like this:

    static void Main(string[] args)
    {
        var reader = new StreamReader(@"myfile.xml");
        var request = WebRequest.Create("http://localhost:41379/mycontroller/import");
        request.Method = "POST";
        request.ContentType = "text/xml";
        StreamWriter sw = new StreamWriter(request.GetRequestStream());
        sw.Write(reader.ReadToEnd());
        sw.Close();
        var theResponse = (HttpWebResponse)request.GetResponse();
        StreamReader sr = new StreamReader(theResponse.GetResponseStream());
        var response = sr.ReadToEnd();
    }

The controller gets called properly, but when I break in there, the argument is null. I am pretty sure I am just not setting the right content type or something like that. What is the proper way to encode the xml so that the framework will get it and give it to the controller properly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:39:14+00:00Added an answer on May 23, 2026 at 7:39 am

    Save yourself a lot of grief and use WebClient.UploadFile.

    Having led you the wrong way, I wrote a controller and client that seem to work fine:

    Controller

    public class HomeController : Controller
    {
        public ActionResult Upload()
        {
            XDocument doc;
            using (var sr = new StreamReader(Request.InputStream))
            {
                doc = XDocument.Load(sr);
            }
            return Content(doc.ToString());
        }
    }
    

    client

    static void Main(string[] args)
    {
    
        var req = (HttpWebRequest)WebRequest.Create("http://host/Home/Upload");
        req.Method = "POST";
        req.ContentType = "text/xml";
    
        using (var stream = File.OpenRead("myfile.xml"))
        using (var requestStream = req.GetRequestStream()) {
            stream.CopyTo(requestStream);
        }
    
    
        using (var response = (HttpWebResponse) req.GetResponse())
        using (var responseStream = response.GetResponseStream())
        using (var sr = new StreamReader(responseStream))
        {
            XDocument doc = XDocument.Load(sr);
            Console.WriteLine(doc);
        }
    
    
        Console.ReadKey();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a controller method that looks like this: [AcceptGet] public ActionResult Index(SecurityMatrixIndexViewModel model)
I have a controller method in ASP.NET MVC that looks like this: public ActionResult
I have a controller that looks like this: public ActionResult Sold() { using (WipDBEntities
I have a Controller that currently looks like this: public ActionResult Index() { var
I have a basic Spring MVC controller that looks like this: @Controller public void
In ASP.NET MVC I have a controller that looks somehow like this: public class
I have a Security class that looks like this: package controllers; import play.Logger; public
I have a simple Controller that looks like this:- @Controller @RequestMapping(value = /groups) public
I have a json array in my Particles controller that looks like this after
If I have a model named Client and controller that looks like this class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.