Skip to content

Get XML with cURL

You can request XML from an endpoint by letting cURL make its usual GET request and adding an Accept header that names XML as the preferred response format.

OUTPUT FORMATSHTMLJSONMarkdown

No separate XML command is needed: the header is the part that steers content negotiation, while GET remains the default method.

Request XML in one command

Point cURL at the XML endpoint and add the Accept header shown in the example below. Because GET is already cURL's default request method, you do not need to state it explicitly for this basic request. The hosted HTTPBin XML endpoint is a useful test target when you want to inspect an XML response without building a server first.

Checklist before you run it

Use this quick check before running the command:

  • Confirm the endpoint can return XML.
  • Confirm the URL is the one you intend to test.
  • Add an Accept header set to application/xml.
  • Leave the method as GET unless the endpoint requires something else.
  • Inspect the returned body to confirm it is XML rather than an error page or another format.

If the response is not XML, check the endpoint's supported formats and whether it honours the Accept header; the header expresses a preference and does not force every server to comply.

The pieces in plain terms

cURL handles the transfer from the command line. A GET request asks the server for a named resource. XML is a data-oriented markup format designed for transport and storage, readable by both people and machines. An HTTP header supplies extra context alongside a message, and here the Accept header carries the format preference to the server.

Related cURL tasks

Related cURL tasks build on the same pattern of choosing a method, adding headers, and handling the response: sending a GET request, using Basic Auth, posting JSON, downloading a file, following redirects, requesting JSON, handling invalid or self-signed certificates, sending a DELETE request, and sending a custom HTTP header. A broader curl web scraping tutorial can help you combine those pieces into a scraping workflow.

Parts of the request
PartRole in this request
cURLCommand-line tool that transfers data between client and server
GET requestAsks the server for a specified resource; cURL's default method
Accept headerStates the preferred response format
application/xmlValue used here to prefer XML
XMLMarkup format for transporting and storing data

The Accept header is a preference; a server may still return another format.

Frequently asked questions

What is cURL?

cURL is a command-line program for moving data between a client and a server. It works with many protocols, including HTTP and FTP, and is commonly used to test APIs, download files, and carry out other network tasks.

What is a GET request?

A GET request asks a server to return a specified resource, such as a page or image. The server responds with the requested data or indicates that it cannot be found.

What is XML?

XML is a markup format intended for carrying and storing data rather than presenting it visually. It can be read by people and processed by machines, and it is a W3C Recommendation.

What is an HTTP header?

HTTP headers travel with a request or response body and add context about that message. In this task, the Accept header tells the server which response format the client prefers.

curl {{HTTPBIN_BASE_URL}}/xml \
   -H "Accept: application/xml"