Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use curl according to the operation you need: curl 'https://example.com/data.xml' fetches an XML response, -o response.xml saves it, -H 'Accept: application/xml' asks an API for an XML representation, and --data-binary @request.xml -H 'Content-Type: application/xml' sends an XML file as a request body. cURL transfers bytes; it does not parse or validate XML, so inspect the response or pass the saved file to an XML-aware parser.

Choose the XML operation first

“Get XML” can describe three different HTTP tasks. Pick the command that matches your goal:

Goal Command pattern What cURL does
Download a URL that already serves XML curl 'https://example.com/data.xml' Writes the response body to standard output
Save the downloaded body curl -o response.xml 'https://example.com/data.xml' Writes only the body to the named file
Ask an API for an XML representation curl -H 'Accept: application/xml' 'https://example.com/api' Sends a representation preference; the server decides what it supports
Submit XML to an endpoint curl --data-binary @request.xml -H 'Content-Type: application/xml' 'https://example.com/api' Sends the file bytes as the request body and uses POST behavior

The examples use example.com because the correct URL, method, authentication, and media type come from the API you are calling.

Fetch an XML URL

Print the response in your terminal

curl 'https://example.com/data.xml'

cURL writes the received response body to standard output by default. If the server returns XML, you will see those bytes in the terminal. cURL does not examine the body to prove that it is well-formed XML; the cURL man page documents cURL as a transfer tool rather than an XML parser.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Save the body under a chosen name

curl -o response.xml 'https://example.com/data.xml'

-o (or --output) writes the transfer output to the filename you provide. This is the predictable choice for scripts because the local name is explicit.

Use the remote URL filename

curl -O 'https://example.com/data.xml'

Uppercase -O (or --remote-name) derives the local filename from the final path component of the URL. Use it when the server’s path name is the name you want on disk; use lowercase -o when you need a different name.

Inspect headers and confirm what came back

Show headers and body together

curl -i 'https://example.com/data.xml'

-i includes the response headers before the body. This is useful for a quick check of the status line and the server’s declared Content-Type, but the headers and XML are mixed in the terminal output.

Write headers to a separate file

curl -D headers.txt -o response.xml 'https://example.com/data.xml'

-D headers.txt (or --dump-header) stores response headers separately, while -o keeps the body in response.xml. This separation is easier to automate: inspect headers.txt for the HTTP metadata and give response.xml to an XML parser.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The actual body and the declared media type are both important. An Accept header is a request, not a guarantee, so always check the returned headers and content. The cURL tutorial covers response-header inspection.

Ask an API to return XML

Send an XML preference with Accept

curl -H 'Accept: application/xml' 'https://example.com/api'

Accept: application/xml tells the endpoint that your client prefers an XML representation. The endpoint may support that type, choose another representation, or reject the request according to its API contract. cURL cannot make an endpoint produce XML that it does not offer.

Rank #2
Sale
Curly Girl: The Handbook
  • Workman publishing
  • Binding: paperback
  • Language: english

Capture the result for verification

curl -D headers.txt -o response.xml 
  -H 'Accept: application/xml' 
  'https://example.com/api'

Open headers.txt and look for the response’s Content-Type; then inspect response.xml. Do not infer success solely from the fact that the command completed or that the URL contains the word “api.”

Use the media type required by the service

Some XML-based services document text/xml rather than application/xml. Send exactly the type their documentation requires:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -H 'Accept: text/xml' 'https://example.com/api'

The cURL FAQ describes custom headers and XML-oriented HTTP services, including SOAP, WebDAV, and XML-RPC. Those protocols can require additional headers and a particular HTTP method; cURL does not understand their application-level rules.

Send an XML request body

Post an XML file without changing its bytes

Create request.xml with the payload expected by the endpoint, then run:

curl --data-binary @request.xml 
  -H 'Content-Type: application/xml' 
  'https://example.com/api'

--data-binary reads the file and posts its contents without the extra processing associated with form-style data. It preserves newlines, carriage returns, and other bytes in the file. The man page distinguishes this behavior from --data.

Choose text/xml when the API specifies it

curl --data-binary @request.xml 
  -H 'Content-Type: text/xml' 
  'https://example.com/api'

The correct Content-Type is a property of the service contract. Do not switch between media types merely because both contain XML; use the value documented by the endpoint.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Understand –data versus –data-binary

--data (or -d) uses cURL’s regular data-post behavior. When it reads a file, cURL strips carriage returns, newlines, and null bytes. That can be harmless for a compact payload, but it can change the exact file content. --data-binary @request.xml is the safer default when whitespace, line endings, or byte-for-byte preservation matters.

The FAQ also shows a simple XML POST using -d and Content-Type: text/xml; follow the endpoint’s requirements when deciding which form is appropriate.

HTTP methods: why -X alone is not enough

Do not confuse a method token with a body

curl -X POST 'https://example.com/api'

-X (or --request) changes the method string cURL sends. It does not create a request body and does not otherwise change cURL’s selected behavior. To send XML, pair the method required by the service with a data option:

curl -X POST 
  --data-binary @request.xml 
  -H 'Content-Type: application/xml' 
  'https://example.com/api'

A data option supplies the body and selects POST behavior. For a nonstandard operation such as WebDAV PROPFIND, use the method and headers specified by that service:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -X PROPFIND 
  --data-binary @request.xml 
  -H 'Content-Type: application/xml' 
  'https://example.com/webdav/resource'

The cURL HTTP scripting guide uses XML with PROPFIND to illustrate this distinction and cautions that changing the method does not rewrite the rest of cURL’s behavior.

Read, parse, and validate the result outside cURL

cURL transfers content; “to cURL, all contents are alike,” as the project’s FAQ puts it. A successful transfer therefore does not establish that the body is XML, that it is well formed, or that it conforms to an application schema.

  1. Save the body with -o and, when debugging, save headers with -D.
  2. Check the returned Content-Type and inspect the first part of the body for an error page, login response, or other non-XML content.
  3. Pass the saved file to an XML-aware parser or validator appropriate for your language and schema.

Keep this separation in scripts: cURL handles transport and a parser handles XML syntax and validation.

Practical command patterns

Fetch, save, and preserve a diagnostic copy of headers

curl -D response.headers -o response.xml 
  'https://example.com/data.xml'

Request XML and keep the response body separate

curl -D response.headers -o response.xml 
  -H 'Accept: application/xml' 
  'https://example.com/api'

Send XML and save the server response

curl --data-binary @request.xml 
  -H 'Content-Type: application/xml' 
  -o result.xml 
  'https://example.com/api'

These forms make the data flow explicit: request headers are sent with -H, the request body comes from the data option, response headers go to a diagnostic file, and the response body goes to a named XML file.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Common failures and fixes

The terminal shows HTML instead of XML

The URL may return an error page, a login page, or another representation. Re-run with -i or -D headers.txt, check the status and Content-Type, and inspect the body. If an API supports content negotiation, add Accept: application/xml; that remains only a preference.

The saved file has no readable line breaks

If you sent a file with --data, cURL may have removed carriage returns and newlines. Use --data-binary @request.xml when exact bytes matter, then resend.

The server says the request has the wrong media type

Change the Content-Type value to the one documented by the endpoint, commonly application/xml or, for some older services, text/xml. The header describes the request body; Accept describes the response representation you prefer.

The method is correct but the request is empty

-X POST, -X PUT, or another -X option does not supply data. Add the endpoint’s required body option, such as --data-binary @request.xml, and its required headers.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value

The command succeeds but the document is invalid

Transport success and XML validity are separate outcomes. Save the body, inspect it for an error response, and run it through an XML parser or validator. cURL itself will not report well-formedness errors.

A protocol-specific XML call is rejected

SOAP, WebDAV, and XML-RPC may require a specific method, content type, or additional application headers. Consult that service’s protocol documentation and reproduce those requirements with cURL; cURL does not implement the protocol semantics for you.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

cURL versus the output choices

Choice Best for Trade-off
Standard output Quick inspection or piping bytes to another command Not automatically saved; headers are not included unless requested
-o filename Scripts and predictable artifact names You must choose the local filename
-O Keeping the URL’s path-based filename The remote path determines the local name
-i One-screen debugging of headers plus body Headers and XML are mixed together
-D headers.txt with -o response.xml Automation, logging, and later parsing Creates two files to manage
--data Simple form-style data where byte preservation is unimportant Can remove line endings and null bytes when reading a file
--data-binary XML files whose exact bytes should be preserved Still requires the correct method, URL, and content type from the API

Or skip the browser setup

If your actual task is to capture a rendered XML documentation page, API console, or other web page as an image or PDF rather than transfer XML bytes, ScreenshotNeo provides a separate website screenshot API and MCP server. It accepts a URL in one GET request:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo documentation for request options. Before capture, it accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and each response reports its result with X-Page-Verdict and X-Billed headers. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

All plans include the same feature set: full-page capture with lazy images loaded, CSS-selector element capture, dark mode, device presets and custom viewports, retina scale, PDF paper and page controls, HTML/CSS rendering, custom JavaScript and CSS, clicks, waits, request blocking, custom headers and cookies, timezone and geolocation, transparent backgrounds, resizing, configurable caching, signed links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, an OpenAPI specification, and compatible parameter names used by other screenshot APIs. Pricing is Free for 1,000 shots per month with no card, then Starter $5 for 3,000, Growth $15 for 15,000, Pro $39 for 60,000, Scale $99 for 250,000, and Business $249 for 1,000,000; annual billing provides two months free.

Start with 1,000 free screenshots a month—no card required.

Minimal checklist

  • Fetching an existing XML URL: use curl URL.
  • Saving it: add -o filename, or use -O for the URL-derived name.
  • Requesting an XML representation: send Accept: application/xml and verify the actual response.
  • Sending XML: use the documented Content-Type and --data-binary @file.xml when preserving bytes matters.
  • Changing the method: remember that -X alone does not create a body.
  • Validating XML: use a separate XML-aware parser or validator after cURL saves the bytes.

Frequently Asked Questions

Can cURL pretty-print or validate XML for me?

No. cURL transfers the response; use a separate XML formatter, parser, or schema validator after saving the body.

Should I use application/xml or text/xml?

Use the media type required by the endpoint’s documentation. Both appear in XML services, but the server’s contract determines which one is accepted.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Quick Recap

SaleBestseller No. 2
Curly Girl: The Handbook
Curly Girl: The Handbook
Workman publishing; Binding: paperback; Language: english
$8.19
Bestseller No. 3
Bestseller No. 4
SaleBestseller No. 5
A Practical Guide to Curl (Programming Series)
A Practical Guide to Curl (Programming Series)
Used Book in Good Condition
$24.99

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.