Send XML with cURL in Ruby
Paste a curl command that sends XML and get idiomatic Ruby code. We pick the right serialization for net/http and set the correct Content-Type.
Quick answer
To convert a cURL command to Ruby, paste it into the Toolpaper workbench below. It parses the command in your browser and emits idiomatic Ruby code — headers, query string, request body, authentication (Bearer, Basic, API key), and cookies are all wired up automatically. No data is uploaded; conversion is fully client-side.
Prefer a different target? See the full cURL to Ruby reference, or jump to the same guide in JavaScript, Node.js, or Python.
require 'net/http'
require 'uri'
require 'json'
uri = URI("https://api.example.com/users")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == 'https'
request = Net::HTTP::Post.new(uri.request_uri)
request["Content-Type"] = "application/xml"
request.body = "<user><name>Ada</name></user>"
response = http.request(request)
puts response.bodyExample
A representative curl command for this scenario. Paste your own above to convert an exact match.
curl -X POST https://api.example.com/users \
-H "Content-Type: application/xml" \
-d '<user><name>Ada</name></user>'Implementation notes
- Content-Type is detected from -H headers first, then inferred from the body shape when the header is missing.
- The XML body is preserved byte-for-byte; only Content-Type and Content-Length are managed for you.
- Charset directives on Content-Type (e.g. application/json; charset=utf-8) survive the round trip.
Common mistakes
- Setting Content-Type manually and then also using net/http's helper — you end up with duplicate headers or the wrong one wins.
- Mixing form encoding with JSON headers — the server rejects with 400 and it's easy to miss in code review.
- Trusting the browser DevTools "Copy as cURL" to preserve charset — it often drops it. Clean panel restores common defaults.
Common questions
- How is XML encoded in the generated Ruby?
- The XML body is passed through as a string with Content-Type: application/xml preserved.
- Does it preserve Content-Type?
- Yes. The Content-Type header is honored and matched against the body so serialization stays consistent.
- Is anything uploaded?
- No. Parsing and generation happen entirely in your browser.
More payload types in Ruby
Ruby hub →The same guide in other languages
All guides →In JavaScript
/how-to/send-xml-with-curl-in-javascript
In Node.js
/how-to/send-xml-with-curl-in-node
In Python
/how-to/send-xml-with-curl-in-python
In Go
/how-to/send-xml-with-curl-in-go
In PHP
/how-to/send-xml-with-curl-in-php
In Rust
/how-to/send-xml-with-curl-in-rust
In Java
/how-to/send-xml-with-curl-in-java
In Kotlin
/how-to/send-xml-with-curl-in-kotlin
Full Ruby reference on the cURL to Ruby hub, or open the main converter for all 18 targets.