JavaScript/AJAX code for GET XML Example
This JavaScript/AJAX code snippet was generated automatically for the GET XML example.<< Back to the GET XML example
What is XML?
XML (Extensible Markup Language) is an extensible markup language that provides structured information: data, documents, configuration, and more. XML is called extensible because it doesn't fix the markup used in documents: you can create markup according to the needs of a particular area, limited only by the rules of XML syntax. An XML file is a simple text file that uses XML tags to describe the structure of a document, how it is stored and transported, and the data itself.
What is HTTP GET request?
HTTP GET is the most popular of the nine commonly used HTTP methods. The GET request method is used to retrieve data from the specified URL, cannot contain data in the body of the GET request, and should not change the server state. The GET method is defined as idempotent, which means that several similar GET requests should have the same effect on the server as a single request.
Get XML Example
An example of getting to our XML GET request:
An example of a server response to our XML GET request:
Why is it important to send the Accept header in the XML request?
The "Accept: application/xml" header indicates that the client expects to see XML in the server's response. Without this header, the server can return data in a different format.
When the server returns XML in its response, it notifies the client using the "Content-Type: application/xml" response header.
How to view XML directly in the browser?
Most browsers can display XML documents right in the browser. To do this, enter the address of the XML document in the address bar, and the browser will display the XML in a convenient tree format.
How to post XML to the server?
To post XML to the server, you need to make a POST request, include the XML in the request body and specify the correct MIME type. The MIME type for XML is "application/xml". The Accept: application/xml request header tells the server that the client is expecting XML, and the "Content-Type: application/xml" response header indicates that the server returned XML. Below is an example of sending XML to the ReqBin echo URL: