Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Posting xml to server and getting xml response back.

Status
Not open for further replies.

kt366

Programmer
Nov 4, 2002
10
GB
Please could someone explain to me how to post xml to a server and then collect the xml response. At the moment when I post to the server, the response I get is in html format and is simply the page I am posting too? I am new at this, can someone explain to me what I am doing wrong? Thanks
 

Are you talking about AJAX ? XMLHttpRequest, XMLHttpResponse are used to transfer data in XML format(commenly used).

You can easily find tutorials on Ajax, so, google it !!
 
You need to use the HttpWebRequest/Response. Something like:
Code:
public void PostXml(string url, string xml, Encoding enc)
{
  byte[] bytes = enc.GetBytes(xml);
  HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
  request.Method = "POST";
  request.ContentLength = bytes.Length;
  request.ContentType = "text/xml";
  using (Stream requestStream = request.GetRequestStream())
  {
    requestStream.Write(bytes, 0, bytes.Length);
  }
  using (HttpWebResponse response = (HttpWebResponse) request.GetResponse())
  {
    if (response.StatusCode != HttpStatusCode.OK)
    {
      string message = String.Format("POST failed. Received HTTP {0}", response.StatusCode);
      throw new ApplicationException(message);
    }
  }
}

Jon

"I don't regret this, but I both rue and lament it.
 
Thank you, I have used this, but I am still recieving an HTML response. Do you have any suggestions? thanks
 
What are you expecting back? Are you sure you're submitting not a web service, not just a regularly web page serving server?

Jon

"I don't regret this, but I both rue and lament it.
 
I am expecting XML back, I am not submitting to a webservice, the page I am submitting to I have been given by the people who have written the system.
 
2 things could be wrong then.

1. Your XML is not in the correct format.
2. Something is wrong with the web server.

You'll need to contact them to find out which. If there is some documentation post a link and your XML.

Jon

"I don't regret this, but I both rue and lament it.
 
MicrosoftOfficeWebServer: 5.0_Pub Content-Length: 27141 Cache-Control: private Content-Type: text/html; charset=utf-8 Date: Mon, 24 Apr 2006 14:28:32 GMT Server: Microsoft-IIS/6.0 X-AspNet-Version: 1.1.4322 X-Powered-By: ASP.NET
 
The Header I gave you was from the response of the server. The Header I am sending is:
Content-Type: text/xml\r\n\r\n which looks wrong.
 
Are you sure you can submit XML to this webserver?

Jon

"I don't regret this, but I both rue and lament it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top