Use curl according to what you need to do: fetch an XML response, ask an API for an XML representation, or send an XML document as a request body. For a direct download, run curl 'https://example.com/data.xml'; curl prints the response body, but it does not parse or validate the XML.
Get an XML response from a URL
If the URL already serves XML, make a normal GET request:
| # | Preview | Product | Price | |
|---|---|---|---|---|
| 1 |
|
Dan Gookin's Guide to Curl Programming | $11.95 | Buy on Amazon |
| 2 |
|
Curly Girl: The Handbook | $8.19 | Buy on Amazon |
| 3 |
|
The C Programming Language | $42.21 | Buy on Amazon |
| 4 |
|
Curl by Example | $0.99 | Buy on Amazon |
| 5 |
|
A Practical Guide to Curl (Programming Series) | $24.99 | Buy on Amazon |
curl 'https://example.com/data.xml'
The response body goes to standard output, so you can read it in the terminal or pipe it to another program. The URL must actually return XML; curl does not convert HTML, JSON, or another format into XML.
Save the response to a named file
curl -o response.xml 'https://example.com/data.xml'
-o (or --output) writes the transfer output to the filename you specify. Use -O (or --remote-name) when you want curl to derive the local filename from the URL path:
#1 Best Overall
curl -O 'https://example.com/data.xml'
These options save the bytes; they do not check whether the document is well-formed XML. Open the file with an XML-aware parser or validator when correctness matters.
Ask an API to return XML
Many APIs support more than one representation. Express a preference with the HTTP Accept header:
curl -H 'Accept: application/xml' 'https://example.com/api'
This is content negotiation, not a conversion command. The server decides whether it supports application/xml. It may return XML, another supported format, or an error. Always inspect both the response headers and the body.
Inspect headers with the response
curl -i -H 'Accept: application/xml' 'https://example.com/api'
-i (or --include) places the HTTP response headers before the body in standard output. This is convenient for a quick check, but the combined output is not a clean XML file.
Recommended Free Tools
Rank #2
Write headers separately
curl -D headers.txt -o response.xml
-H 'Accept: application/xml'
'https://example.com/api'
-D headers.txt (or --dump-header) stores the headers in one file while -o response.xml stores only the response body in another. Check the server’s Content-Type header and compare it with the document you received. An XML body commonly uses application/xml or another XML media type, but the endpoint’s documentation is authoritative.
Send an XML document in a request
For an XML file used as the request body, preserve the file contents and set the media type required by the API:
curl --data-binary @request.xml
-H 'Content-Type: application/xml'
'https://example.com/api'
@request.xml tells curl to read the body from that local file. --data-binary sends the specified data without the transformations associated with form-style data, preserving newlines, carriage returns, and other bytes. Supplying a data option also makes curl use POST behavior unless you specify a different method required by the service.
When an endpoint documents text/xml
Some services, including certain SOAP-style integrations, document text/xml rather than application/xml. Use the exact media type in that service’s documentation:
Free tools Windows power users keep installed
One-click scans. No signup required.
Rank #3
curl --data-binary @request.xml
-H 'Content-Type: text/xml'
'https://example.com/soap-endpoint'
The header describes the request you are sending. It does not guarantee that the response will also be XML; inspect the response separately.
Use inline XML for a small request
curl --data '<note><to>Sam</to><body>Hello</body></note>'
-H 'Content-Type: application/xml'
'https://example.com/api'
--data is convenient for short text. When reading a file, however, it uses form-style processing and can strip carriage returns, newlines, and null bytes. Choose --data-binary when the exact file bytes and line endings must be retained.
Choose the right command for the operation
| Goal | Command pattern | Result |
|---|---|---|
| Read an existing XML URL | curl 'URL' |
Body printed to standard output |
| Save with your own filename | curl -o response.xml 'URL' |
Body written to response.xml |
| Use the URL’s filename | curl -O 'URL' |
Body saved using the remote path filename |
| Request an XML representation | curl -H 'Accept: application/xml' 'URL' |
Server chooses the representation |
| See headers and body together | curl -i 'URL' |
Headers and body in one stream |
| Keep headers separate | curl -D headers.txt -o response.xml 'URL' |
Headers and body in different files |
| Upload an XML file unchanged | curl --data-binary @request.xml -H 'Content-Type: application/xml' 'URL' |
File sent as the request body |
Understand -X and HTTP methods
-X (or --request) changes the method token curl puts on the request. It does not create a body, add an XML content type, or otherwise change curl’s normal behavior:
curl -X PROPFIND
-H 'Content-Type: application/xml'
--data-binary @request.xml
'https://example.com/webdav/'
Use the method, headers, and body specified by the API. For a normal XML POST, the data option supplies the body and selects POST automatically, so adding -X POST is usually unnecessary. For WebDAV, SOAP, XML-RPC, or another protocol, follow that protocol’s required method and headers. curl transfers the bytes; it does not understand the application-level XML protocol.
Rank #4
Verify that you actually received XML
- Capture the headers. Run
curl -D headers.txt -o response.xml 'URL'and inspect the status code andContent-Type. - Inspect the first lines. A document may begin with an XML declaration such as
<?xml version="1.0"?>, but an XML declaration is optional. Do not treat its absence as proof that the response is not XML. - Check the body for an error page. A failed request can return HTML or plain text even when you expected XML. A successful HTTP status alone does not prove that the payload is valid XML.
- Parse or validate with an XML tool. curl does not establish well-formedness, schema validity, namespaces, or business-rule correctness. Pass the saved file to the XML parser or validator used by your project.
The curl project summarizes this behavior in its FAQ: “To curl, all contents are alike.” See the curl FAQ and curl man page for the transfer options described here.
Troubleshoot common XML requests
You received HTML instead of XML
Check the status code, redirects, authentication, and the response’s Content-Type. Add -i for a quick combined view or -D headers.txt to keep headers separate. An Accept header only expresses a preference; it cannot make an endpoint support XML.
The downloaded file contains headers
You probably used -i together with an output file. Use -D headers.txt -o response.xml when you need separate files. Reserve -i for terminal inspection.
The server says the request body is missing or malformed
Confirm that request.xml exists in the current directory, that the @ prefix is present, and that the endpoint expects the method you used. Use --data-binary when line endings or exact bytes matter, and set the documented Content-Type.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteBest Value
-X changed the method but the request still fails
Changing the method alone does not add a body or the headers required by the application protocol. Add the appropriate data option and headers, or follow the service’s documented request example. The curl HTTP scripting guide demonstrates this distinction with XML requests.
The response is empty or the command appears stuck
Check the URL and network access first, then inspect headers and the HTTP status. A server may be slow, require authentication, or return a response with no body. Keep diagnostics separate from the XML file so an error message cannot be mistaken for document content.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Operational, security, and cost considerations
- Output handling: Use
-ofor deterministic filenames in scripts. Write headers to a different file when a downstream parser expects XML only. - Byte fidelity: Prefer
--data-binaryfor signed, canonicalized, or whitespace-sensitive XML. Use--dataonly when its form-style processing is acceptable. - Credentials: Avoid placing secrets directly in shell history. Use the authentication mechanism documented by the endpoint and protect any saved header files.
- Validation: Treat transport success and XML validity as separate checks. A 2xx response can still contain an application error document or malformed content.
- Protocol behavior: SOAP, WebDAV, and XML-RPC may require special methods, headers, and envelopes. curl supplies the HTTP exchange but does not implement those application protocols.
Or skip the browser setup
If your broader task is to capture how an XML-backed page renders in a browser rather than retrieve its raw XML bytes, ScreenshotNeo provides a single-call screenshot API. It is separate from XML parsing: use curl and an XML parser for machine-readable XML, and use ScreenshotNeo when you need a rendered PNG, JPEG, WebP, or PDF.
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 API documentation for request options. Before capture, it can accept cookie or consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing result. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients. The Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 shots.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Create a free ScreenshotNeo account to try the 1,000 monthly screenshots without a card.
Further reading
- curl man page — output and request-body options.
- curl FAQ — XML POSTs, content types, and HTTP-based XML protocols.
- curl HTTP scripting guide — custom methods and XML request examples.
- curl tutorial — inspecting response headers.
Frequently Asked Questions
Can an Accept header convert a JSON endpoint into XML?
No. It communicates a preferred representation. The server must implement XML; otherwise inspect the returned media type and body and use the format the endpoint supports.
Should I use --data or --data-binary for an XML file?
Use --data-binary when preserving the file’s exact bytes, newlines, or carriage returns matters. Use --data only when its form-style processing is acceptable.
Does curl validate an XML schema?
No. curl transfers content. Save the response and run it through a separate XML parser or schema-validation tool.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Quick Recap
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.

