To receive XML from the server, you need to send a GET request and specify the Accept: application/xml header in the request. The Accept header tells the server that your client is expecting XML data. Without this header, the server may return data in a different format. The Content-Type: application/xml response header informs the client that the server returned XML. In this GET XML Example, we are sending a GET request to the ReqBin echo URL. Click Send to execute the GET XML request online and see the results. The Python code was automatically generated for the GET XML example.
XML (eXtensible Markup Language) is an extensible markup language built using simple formal syntax that is both human-readable and machine-readable. The main goal of XML design is versatility, simplicity, and usability on the web. An XML file is a simple text format that uses custom XML tags to describe the structure of a document and how it should be stored and transported. XML is called extensible because it does not capture the markup used in documents: you can create markup according to the needs of a specific area, limited only by the rules of XML syntax.
HTTP GET is the most popular of the nine commonly used HTTP methods. GET request method is used to retrieve data from the specified URL. GET method requests should only receive data. GET cannot accept data in the body of a GET message and should not affect data on the server.
HTTP GET Request Example
GET /echo/ HTTP/1.1
Why is it important to send the Accept header with the XML request?
Your client needs to indicate what the XML expects by sending an Accept: application/xml header to receive the XML from the server. Without this header, the server may return data in a different format.
Accept Header Example
If the server returned XML in its response, it notifies the client using the Content-Type: application/xml response header.
Content-Type Response Header Example
Get XML request Example
An example of a server response to our XML GET request:
Server XML Response Example
HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8