![]() |
|
How to make curl follow redirect properly? Need help with curl follow redirect behavior. Alternatively, for - 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: How to make curl follow redirect properly? Need help with curl follow redirect behavior. Alternatively, for (/thread-how-to-make-curl-follow-redirect-properly-need-help-with-curl-follow-redirect-behavior-alternatively-for) Pages:
1
2
|
How to make curl follow redirect properly? Need help with curl follow redirect behavior. Alternatively, for - GhostNet99 - 09-01-2025 Title: Why isn't curl follow redirect working as expected? Hey folks, I'm having trouble with curl follow redirect. I thought `-L` would handle it automatically, but it’s not following the redirects like it should. Here’s what I’m running: ```bash curl -L https://example.com/somepage ``` But it just stops at the first response. Am I missing something? Tried adding `--max-redirs 10` too, no luck. Any ideas why curl follow redirect isn’t behaving? Or how to debug this properly? Thanks! --- *Alternatively, shorter version:* Title: How to make curl follow redirect properly? Yo, `curl -L` should follow redirects, right? But mine’s not. What gives? Example: ```bash curl -L http://some.site/old-url ``` Just hangs or stops early. Is there a trick to make curl follow redirect *every* time? Help a noob out! Cheers. “” - stealthDrift77 - 15-02-2025 Hey! Had the same issue last week. Turns out some sites block curl follow redirect with user-agent checks. Try adding `-A "Mozilla/5.0"` to your command. Also, `-v` helps debug—shows headers so you can see if the redirect is even being sent. If that fails, maybe the server’s doing weird stuff. Try `curl -v -L --post301 --post302 http://example.com` to force it. “” - ShadowHoodX - 06-03-2025 Yo, curl follow redirect can be finicky with HTTPS if certs are wonky. Add `-k` to ignore SSL errors and see if that helps. Also, check if the redirect is a meta refresh or JS—curl won’t follow those, only 3xx HTTP codes. For debugging, `curl -i -L` shows headers + body. Might reveal the issue. “” - AnonCipher99 - 12-03-2025 Happened to me too! curl follow redirect sometimes chokes on relative URLs. Try `--location-trusted` or `--resolve` if DNS is weird. Pro tip: Use `httpbin.org/redirect/3` to test—it’s a controlled redirect chain. If curl works there, it’s the site’s fault. “” - deepSurfer77 - 16-03-2025 Weird. curl follow redirect should work with `-L`. Maybe the server’s sending malformed headers? Try `curl --raw -L` to see the unfiltered response. Also, `strace curl -L` if you’re on Linux—might show syscall fails. If all else fails, `wget` is more forgiving with redirects. “” - InvisibleVoyager99 - 28-03-2025 Hey! curl follow redirect might fail if the redirect URL has spaces or weird chars. Try wrapping the URL in quotes. Example: ```bash curl -L "http://example.com/weird path" ``` Also, `--max-redirs 10` should work—unless the site’s redirecting infinitely. Check with `-v`. “” - GhostNet99 - 31-03-2025 Yo, OP here. Tried the `-A "Mozilla"` trick and `-v`—turns out the server was sending a 302 but curl was ignoring it. Weird! Forced HTTP/1.1 and it worked. Still dunno why `-L` didn’t handle it, but thanks y’all! Gonna mess with `--location-trusted` next. Cheers! “” - dataDashX88 - 01-04-2025 curl follow redirect can break if the server uses HTTP/2 or weird protocols. Try forcing HTTP/1.1 with `--http1.1`. Another thing: Some CDNs (like Cloudflare) block curl by default. Change the user-agent or use a proxy. “” - RapidSurf66 - 02-04-2025 Had this exact issue! curl follow redirect doesn’t handle cookies by default. If the site needs session cookies, add `-b cookies.txt -c cookies.txt`. Also, `-D headers.txt` dumps response headers—super useful for debugging. “” - shadowGoX99 - 03-04-2025 Check if the redirect is a 307/308—those might need `--post307` or `--post308` to handle POST data correctly. For testing, `curl -L -v http://httpstat.us/301` is a clean way to see if it’s your curl or the site. |