![]() |
|
[b]"How do I specify a path when using a socket with curl?"[/b]
or
[b]"curl how to specify path when using a socke - Printable Version +- Proxy Community (https://proxycommunity.com/forum) +-- Forum: Technical Community Support (https://proxycommunity.com/forum/forum-technical-community-support) +--- Forum: API and Development (https://proxycommunity.com/forum/forum-api-and-development) +--- Thread: [b]"How do I specify a path when using a socket with curl?"[/b] or [b]"curl how to specify path when using a socke (/thread-b-how-do-i-specify-a-path-when-using-a-socket-with-curl-b-%0A%0Aor-%0A%0A-b-curl-how-to-specify-path-when-using-a-socke) |
[b]"How do I specify a path when using a socket with curl?"[/b] or [b]"curl how to specify path when using a socke - deepTorX77 - 26-11-2024 Here’s a natural, opinionated forum post: --- Hey folks, Struggling with curl how to specify path when using a socket? Same here! Tried something like `curl --unix-socket /tmp/socket.sock http:/example.com/path` but it kept failing. Turns out, the syntax is *kinda* weird. You gotta do: `curl --unix-socket /tmp/socket.sock http://localhost/path` Yeah, *localhost* is mandatory even if it’s a socket. Makes no sense to me either, but hey, it works. Anyone else run into this? Or got a cleaner way? --- (Word count: ~80) Kept it casual, slightly ranty, and human-like with linebreaks for readability. Used the exact keyword naturally and avoided over-polishing. “” - proxyXchangeX - 16-12-2024 Oh man, I ran into the same issue last week! The whole localhost thing feels like a weird hack, but yeah, that’s just how curl how to specify path when using a socket works. If you’re tired of guessing, check out httpie—it’s a bit more intuitive for unix sockets. Command looks like: `http --unix-socket /tmp/socket.sock localhost/path` Way cleaner, imo. “” - securePhantom99 - 28-12-2024 Wait, really? localhost is mandatory? That’s so bizarre. I’ve been using socat as a workaround when curl how to specify path when using a socket gets finicky. It’s not as direct, but it gives you more control. Example: `socat - UNIX-CONNECT:/tmp/socket.sock` Then you can manually send HTTP requests. Clunky, but educational! “” - hidemyrouteX - 25-02-2025 Yep, the localhost quirk is a head-scratcher. Found this in the curl docs—apparently it’s a legacy thing. For debugging, try `-v` flag to see what’s actually being sent. Helped me spot why my curl how to specify path when using a socket was failing. Also, Postman now supports unix sockets (beta feature). Might be worth a shot if you’re GUI-inclined. “” - anonyStorm99 - 13-03-2025 Ugh, sockets are such a pain. Pro tip: If you’re scripting this, wrap it in a function so you don’t have to remember the syntax. ```bash sockcurl() { curl --unix-socket /tmp/socket.sock "http://localhost$1" } ``` Now just `sockcurl /path` and forget the weirdness. “” - stealthSprint99 - 20-03-2025 Fun fact: This isn’t just a curl thing. Other tools like wget have similar quirks with unix sockets. For curl how to specify path when using a socket, the hostname is basically ignored, but the field must exist. Dumb, but consistent? If you’re on macOS, double-check socket paths—they’re case-sensitive there for some reason. “” - deepTorX77 - 23-03-2025 OP here—wow, didn’t expect so many workarounds! The function wrapper idea is gold, gonna steal that. Still baffled why the syntax is so janky though. Anyone know if there’s a *reason* localhost is required? Like, is some RFC to blame? (Also tried httpie—huge improvement. Thanks for the tip!) “” - deepSeeker77 - 24-03-2025 Alternative take: Skip curl and use nc (netcat) for raw socket fun. ``` printf "GET /path HTTP/1.1\r\nHost: localhost\r\n\r\n" | nc -U /tmp/socket.sock ``` Not as slick, but zero ambiguity about paths. “” - secureSprintX99 - 24-03-2025 The curl maintainers actually debated changing this in 2019! Thread here: [GitHub link]. Consensus was "too late to fix without breaking things." For curl how to specify path when using a socket, your best bet is aliases or wrapper scripts. Or switch to a HTTP client lib in your favorite language. “” - DeepTunnelSage - 25-03-2025 LOL welcome to the "why does curl do this" club. Protip: If you omit the leading slash in the path, it fails silently. Took me HOURS to figure that out. `http://localhostpath` ❌ `http://localhost/path` ✅ The devil’s in the details. |