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

  • Home
  • SEARCH
  • 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 406611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:30:47+00:00 2026-05-12T17:30:47+00:00

I need to post raw xml to a site and read the response. With

  • 0

I need to post raw xml to a site and read the response. With the following code I keep getting an “Unknown File Format” error and I’m not sure why.

            XmlDocument sampleRequest = new XmlDocument();
            sampleRequest.Load(@"C:\SampleRequest.xml");
            byte[] bytes = Encoding.UTF8.GetBytes(sampleRequest.ToString());

            string uri = "https://www.sample-gateway.com/gw.aspx";
            req = WebRequest.Create(uri);
            req.Method = "POST";
            req.ContentLength = bytes.Length;
            req.ContentType = "text/xml";

            using (var requestStream = req.GetRequestStream())
            {
                requestStream.Write(bytes, 0, bytes.Length);
            }

            // Send the data to the webserver
            rsp = req.GetResponse();

            XmlDocument responseXML = new XmlDocument();
            using (var responseStream = rsp.GetResponseStream())
            {
                responseXML.Load(responseStream);
            }

I am fairly certain my issue is what/how I am writing to the requestStream so..

How can I modify that code so that I may write an xml located on the hard drive to the request stream?

  • 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-12T17:30:48+00:00Added an answer on May 12, 2026 at 5:30 pm

    ok instead of doing sampleRequest.ToString(), you should use sampleRequest.OuterXml, and that would do the magic, you were sending “System.Xml.XmlDocument” instead of the Xml

        XmlDocument sampleRequest = new XmlDocument();
        sampleRequest.Load(@"C:\SampleRequest.xml");
        //byte[] bytes = Encoding.UTF8.GetBytes(sampleRequest.ToString());
        byte[] bytes = Encoding.UTF8.GetBytes(sampleRequest.OuterXml);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to POST data to a url in the middle of a script.
I have an action which I need to post forward onto another action if
I am working on a ASP.NET app and i have a need to post
I need to capture the HTML and do some post processing on the HTML
I need to send PUT and DELETE along with POST, GET to a REST
I have a similar problem to this post . I need to display up
Need to locate the following pattern: The letter I followed by a space then
Need a function that takes a character as a parameter and returns true if
Need a way to allow sorting except for last item with in a list.
Need to an expression that returns only things with an I followed by either

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.