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 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 have a need to do RAW POST (PUT a $var) requests to a
I don't think I need to post my code (there's lots of it) but
I need to read a large (2000x2000) matrix of binary data from a file
I need to POST a Guid and an int value onto an MVC3 site.
I need to send raw data in the body of a POST request to
I read the following post with interest as it is an exact replica of
i need to send raw multipart data with a php POST but without an
I need to analyse a binary data file containing raw data from a scientific
I need to post to a REST resource by using ruby rest-client gem. The
I need to POST data to a url in the middle of a script.

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.