We help IT Professionals succeed at work.
Get Started

How can I get an XML response from a request to a remote server?

YPU asked
Last Modified: 2015-03-11
We are setting up recurring billing on our web app and we are going to be using Cheddar Getter Here's the request dictionary.

We are going to use an existing wrapper written in C# (see it here here)

The problem is, the way the original wrapper was written, we are receiving an http response from the server, and not the xml that the server sends back.

Here is an example method that I've been trying to get to return the xml from Cheddar Getter:

        private static string postRequest(string urlBase, string urlPath, string postParams)
            string result = "";

                HttpWebRequest request = WebRequest.Create(urlBase + urlPath) as HttpWebRequest;

                //Add authentication
                request.Credentials = new NetworkCredential(_Username, _Password);

                //make into a post
                request.ContentType = "application/x-www-form-urlencoded";
                request.Method = "POST";

                byte[] bytes = Encoding.UTF8.GetBytes(postParams);
                request.ContentLength = bytes.Length;

                using (Stream requestStream = request.GetRequestStream())
                    requestStream.Write(bytes, 0, bytes.Length);

                    using (WebResponse response = request.GetResponse())
                        using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                            result = reader.ReadToEnd();

            catch (Exception ex)
                throw ex;

            return result;

Open in new window

Using the above method with incomplete data (we're trying to get the gooey details of an error returned from Cheddar Getter), as soon as you call

using (WebResponse response = request.GetResponse())

Open in new window

a server error is returned (412). This is not desirable, as Cheddar Getter provides XML output with more detailed information about the error (missing name, invalid CC, etc).

If anyone could point me in the right direction, that would be awesome!
Watch Question
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE