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

To log in with cURL, fetch the login page, preserve its cookies, submit the form’s actual fields—including hidden CSRF or state values—and reuse the resulting cookies for protected pages. The exact endpoint and parameters depend on the website. cURL can handle HTTP requests and cookies, but it does not run a page’s JavaScript or complete interactive challenges such as CAPTCHA, WebAuthn, or MFA.

Identify what kind of login the site uses

Before sending credentials, determine whether the server expects an HTML form submission or HTTP authentication. These are different mechanisms: a command that works for one will not necessarily work for the other.

Browser-style form login

Most website logins use a form: the browser sends a POST containing credentials and sometimes hidden values, then retains cookies that represent the session. The curl project’s authentication guide notes that most modern websites do not use HTTP authentication for ordinary logins; they ask users to log in on webpages and then maintain a session with cookies. The project’s guide to HTTP POST describes the practical task as identifying the data to submit and the target URL.

HTTP authentication

If the server challenges a protected URL with HTTP Basic authentication, use -u or --user. For other HTTP authentication methods, cURL can be asked to select a method offered by the server with --anyauth. These options do not submit a normal website form.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Amazon Basics Wired QWERTY Keyboard, Works with Windows, Plug and Play, Easy to Use with Media Control, Full-Sized, Black
  • KEYBOARD: The keyboard works for Windows with hot keys that enable easy access to Media, My Computer, Mute, Volume up/down, and Calculator
  • EASY SETUP: Experience simple installation with the USB wired connection
  • VERSATILE COMPATIBILITY: This keyboard is designed to work with multiple Windows versions, including Vista, 7, 8, 10 offering broad compatibility across devices.
  • SLEEK DESIGN: The elegant black color of the wired keyboard complements your tech and decor, adding a stylish and cohesive look to any setup without sacrificing function.
  • FULL-SIZED CONVENIENCE: The standard QWERTY layout of this keyboard set offers a familiar typing experience, ideal for both professional tasks and personal use.

Log in with a website form and keep the session

Replace the example domain, form action, field names, and token below with the values from the site you are authorized to access. The commands assume a URL-encoded form and a shell compatible with backslash line continuation.

  1. Fetch the login page and save its cookies.
    curl -sS -c cookies.txt https://example.com/login -o login.html
    This writes response cookies to cookies.txt and saves the HTML locally. The cookie jar matters because a site may issue a session cookie before the form is submitted.
  2. Inspect the HTML form.
    Open login.html and locate the form’s action and method, the names of the username and password fields, and any hidden inputs. A hidden CSRF token or state value may be required. Use the form’s actual destination, not an assumed URL.
  3. Submit the form while reading and updating the same cookie jar.
    curl -sS -L -b cookies.txt -c cookies.txt
      --data-urlencode 'username=USER'
      --data-urlencode 'password=PASS'
      --data-urlencode 'csrf_token=TOKEN'
      https://example.com/session

    Replace https://example.com/session with the form action and replace each example field with the exact field name and value the site expects. Include every required hidden input. The -b option sends cookies already in the jar; -c saves cookies received in the response. -L follows redirects.
  4. Request a protected page using the jar.
    curl -sS -b cookies.txt https://example.com/account
    Check that the response is the expected account page, not a login page returned with a successful HTTP status.

For a simple form without hidden inputs, omit the token parameter. For a site that expects multipart form data, use -F or --form instead of --data-urlencode; follow the site’s actual form encoding requirements.

Handle hidden tokens, encodings, and redirects

CSRF and state values

Many sites require a token that is generated when the login page loads. Fetch the page first, retain its cookies, extract the current token, then submit that token with the same session. A stale token, a missing hidden field, or cookies from a different session can cause a 403 response or an invalid-form error. Official cURL guidance notes that browser-like scripts may need to extract hidden values and send them with the POST.

Rank #2
Sale
Logitech MK270 Full Size Wireless Keyboard and Mouse Combo - Black
  • Reliable Plug and Play: The USB receiver provides a reliable wireless connection up to 33 ft (1), so you can forget about drop-outs and delays and you can take it wherever you use your computer
  • Type in Comfort: The design of this keyboard creates a comfortable typing experience thanks to the low-profile, quiet keys and standard layout with full-size F-keys, number pad, and arrow keys
  • Durable and Resilient: This full-size wireless keyboard features a spill-resistant design (2), durable keys and sturdy tilt legs with adjustable height
  • Long Battery Life: MK270 combo features a 36-month keyboard and 12-month mouse battery life (3), along with on/off switches allowing you to go months without the hassle of changing batteries
  • Easy to Use: This wireless keyboard and mouse combo features 8 multimedia hotkeys for instant access to the Internet, email, play/pause, and volume so you can easily check out your favorite sites

Choose the request encoding the form expects

  • --data-urlencode 'name=value' is useful for URL-encoded fields, especially values containing spaces or reserved characters.
  • --data 'name=value' sends form data without the same automatic URL-encoding behavior; use it only when the values and expected encoding make that appropriate.
  • --form 'name=value' sends multipart form data. Use it when the form or endpoint expects multipart/form-data.

Know what redirect following does

With -L (also called --location), cURL follows redirects after the login request. For 301, 302, and 303 responses, cURL can change a POST into a GET; 307 and 308 preserve the method. If the final page is unexpected, inspect the response headers and redirect destination rather than assuming the form submission succeeded. Avoid --location-trusted unless you have a specific, safe reason to use it: it can allow credentials and other secrets to be forwarded across hosts.

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

Use cURL for HTTP Basic authentication

If the endpoint uses HTTP Basic authentication, a request looks like this:

curl -u 'USER:PASS' https://example.com/protected

Use the authentication mechanism the server actually requests. The -u option is not a substitute for posting a username and password to a website’s HTML form. If the server offers a choice of HTTP authentication methods, --anyauth lets cURL select from methods the server offers; --basic forces Basic authentication.

Rank #3
Sale
Logitech K120 Full Size Wired Keyboard USB Plug-and-Play Windows - Black
  • All-day Comfort: The design of this standard keyboard creates a comfortable typing experience thanks to the deep-profile keys and full-size standard layout with F-keys and number pad
  • Easy to Set-up and Use: Set-up couldn't be easier, you simply plug in this corded keyboard via USB on your desktop or laptop and start using right away without any software installation
  • Compatibility: This full-size keyboard is compatible with Windows 7, 8, 10 or later, plus it's a reliable and durable partner for your desk at home, or at work
  • Spill-proof: This durable keyboard features a spill-resistant design (1), anti-fade keys and sturdy tilt legs with adjustable height, meaning this keyboard is built to last
  • Plastic parts in K120 include 51% certified post-consumer recycled plastic*

Verify that you are actually logged in

A command can complete without a network error and still leave you anonymous. Confirm the result with more than the shell exit status: inspect the HTTP response, the final URL after redirects, or a marker that appears only on the authenticated page.

  • Use -i to include response headers in the output when diagnosing a request.
  • Use -D headers.txt to save response headers for inspection.
  • Check whether the server returns the expected protected content rather than redirecting back to the login form.
  • For subsequent requests, keep using -b cookies.txt. If the site rotates cookies during login, ensure the login command also writes updated cookies with -c cookies.txt.

Troubleshoot common cURL login failures

Symptom Likely cause What to check or change
401 Unauthorized The request uses the wrong authentication method, or credentials are rejected. Determine whether the endpoint expects HTTP authentication, a form POST, a bearer token, or another scheme. -u only handles HTTP authentication.
403 Forbidden or invalid form A hidden field, CSRF token, or original session cookie is missing or stale. Fetch the login page again, keep its cookie jar, and submit all required hidden values from that page with the matching session cookie.
Redirect loop or unexpected destination The form action or redirect host may be wrong; the server may also expect different handling after the POST. Inspect headers with -i or -D headers.txt, verify the form action, and account for POST-to-GET changes on 301/302/303 redirects.
Login appears to work, but the next page is anonymous The follow-up request did not send the same session cookies, or cookie domain/path rules do not match. Use the same jar for both requests: -b cookies.txt -c cookies.txt on the login request and -b cookies.txt on the protected request. Confirm the protected URL is within the cookie’s scope.
HTML response contains a challenge or never reaches the account page The flow may depend on JavaScript or an interactive security step. Use the site’s documented API or an approved browser automation flow for JavaScript, CAPTCHA, WebAuthn, or MFA challenges. cURL does not execute browser JavaScript or complete interactive prompts.

Protect credentials and session cookies

Use HTTPS so credentials and cookies are encrypted in transit. Avoid putting reusable passwords directly in shell commands when possible: command text may remain in shell history or be visible in process listings. Treat cookies.txt as a secret because it may grant access to the account; keep it out of shared directories and delete it when no longer needed. Do not send credentials to a host you have not verified, and do not use --location-trusted casually because it may forward secrets to another host.

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

Or skip the browser setup

If your goal is to capture a page rather than automate a site login, ScreenshotNeo is a website screenshot API and MCP server from Yorker Media. It does not log in to accounts on your behalf; use it only for pages you can access without an interactive login flow. Its API returns an image or PDF from one GET request, and the API options and details are in the ScreenshotNeo documentation.

Rank #4
Redragon K521 Upgrade Rainbow LED Gaming Keyboard, 104 Keys Wired Mechanical Feeling Keyboard with Multimedia Keys, One-Touch Backlit, Anti-Ghosting, Compatible with PC, Mac, PS4/5, Xbox
  • 【Dreamy Rainbow Gaming Keyboard】K521 Gaming Keyboard Adopts a Different LED Backlight Design, Upgraded on the Traditional LED Backlight Effect, Making the Light More Penetrating, Giving You a More Dazzling Visual Effect, Making Your Gaming Process More Enjoyable
  • 【One Touch Opens & Visual Feast】The K521 Red Dragon Keyboard has a One-Touch on/off Lighting Button for Added Convenience. It also has a Three-Position Adjustable Breathing Mode and a Four-Position Adjustable Brightness Lighting Mode
  • 【Mechanical Feeling & Fast Tapping】The PC Keyboard Keys are Designed for Mechanical Feeling, Giving You a Better Feel During Use and the Ability to Trigger Keys Quickly, Allowing You to Win All Your Games
  • 【19 Keys Anti-Ghosting Keyboard】Anti-Ghosting Ensures Every Button Can Be Triggered. This Allows You to Trigger Key Combinations In The Game Accurately, And Each Skill Can Be Accurately Released to Increase Your Winning Rate. Redragon K521 Will Be Your Perfect Partner
  • 【12 Multimedia Combination Keys】The K521 Wired Gaming Keyboard is Equipped with 12 Multimedia Keys That Can Greatly Enhance Your Gaming/Office Efficiency and Make It More Convenient to Use

Example cURL request for a publicly accessible page:

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

ScreenshotNeo removes supported cookie/consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, failed loads, timeouts, and cache hits are not billed. Its MCP server provides screenshot tools for AI agents, and the Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for 1,000 free screenshots a month with no card.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Frequently Asked Questions

Can cURL log in when a website requires MFA?

Not reliably for interactive MFA. Use the site’s documented API or an approved browser automation flow when a challenge must be completed.

Best Value
Sale
Logitech K270 Full Size Wireless Keyboard for Windows - Black
  • All-day Comfort: This USB keyboard creates a comfortable and familiar typing experience thanks to the deep-profile keys and standard full-size layout with all F-keys, number pad and arrow keys
  • Built to Last: The spill-proof (2) design and durable print characters keep you on track for years to come despite any on-the-job mishaps; it’s a reliable partner for your desk at home, or at work
  • Long-lasting Battery Life: A 24-month battery life (4) means you can go for 2 years without the hassle of changing batteries of your wireless full-size keyboard
  • Simply plug the USB receiver into a USB port on your desktop, laptop or netbook computer and start using the keyboard right away without any software installation
  • Simply Wireless: Forget about drop-outs and delays thanks to a strong, reliable wireless connection with up to 33 ft range (5); K270 is compatible with Windows 7, 8, 10 or later

Does cURL save login cookies automatically?

Only when you tell it to write them, such as with -c cookies.txt; send them on later requests with -b cookies.txt.

Can I use cURL to capture a screenshot of a logged-in page?

cURL retrieves HTTP responses; it does not render a page as a browser screenshot. Use a browser automation flow for authenticated pages or a screenshot service for pages accessible without interactive login.

Quick Recap

Bestseller No. 1
SaleBestseller No. 3
Logitech K120 Full Size Wired Keyboard USB Plug-and-Play Windows - Black
Logitech K120 Full Size Wired Keyboard USB Plug-and-Play Windows - Black
Plastic parts in K120 include 51% certified post-consumer recycled plastic*; Product carbon footprint: 4.02 kg CO2e
$12.34
SaleBestseller No. 5
Logitech K270 Full Size Wireless Keyboard for Windows - Black
Logitech K270 Full Size Wireless Keyboard for Windows - Black
Plastic parts in K270 include 38% certified post-consumer recycled plastic; Eight hot keys: For instant access to the Internet, e-mail, music volume and more
$21.48

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.

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