• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# The Art Of Scripting HTTP Requests Using Curl
2
3## Background
4
5 This document assumes that you're familiar with HTML and general networking.
6
7 The increasing amount of applications moving to the web has made "HTTP
8 Scripting" more frequently requested and wanted. To be able to automatically
9 extract information from the web, to fake users, to post or upload data to
10 web servers are all important tasks today.
11
12 Curl is a command line tool for doing all sorts of URL manipulations and
13 transfers, but this particular document will focus on how to use it when
14 doing HTTP requests for fun and profit. I will assume that you know how to
15 invoke `curl --help` or `curl --manual` to get basic information about it.
16
17 Curl is not written to do everything for you. It makes the requests, it gets
18 the data, it sends data and it retrieves the information. You probably need
19 to glue everything together using some kind of script language or repeated
20 manual invokes.
21
22## The HTTP Protocol
23
24 HTTP is the protocol used to fetch data from web servers. It is a very simple
25 protocol that is built upon TCP/IP. The protocol also allows information to
26 get sent to the server from the client using a few different methods, as will
27 be shown here.
28
29 HTTP is plain ASCII text lines being sent by the client to a server to
30 request a particular action, and then the server replies a few text lines
31 before the actual requested content is sent to the client.
32
33 The client, curl, sends a HTTP request. The request contains a method (like
34 GET, POST, HEAD etc), a number of request headers and sometimes a request
35 body. The HTTP server responds with a status line (indicating if things went
36 well), response headers and most often also a response body. The "body" part
37 is the plain data you requested, like the actual HTML or the image etc.
38
39## See the Protocol
40
41 Using curl's option [`--verbose`](https://curl.se/docs/manpage.html#-v)
42 (`-v` as a short option) will display what kind of commands curl sends to the
43 server, as well as a few other informational texts.
44
45 `--verbose` is the single most useful option when it comes to debug or even
46 understand the curl<->server interaction.
47
48 Sometimes even `--verbose` is not enough. Then
49 [`--trace`](https://curl.se/docs/manpage.html#-trace) and
50 [`--trace-ascii`](https://curl.se/docs/manpage.html#--trace-ascii)
51 offer even more details as they show **everything** curl sends and
52 receives. Use it like this:
53
54    curl --trace-ascii debugdump.txt http://www.example.com/
55
56## See the Timing
57
58 Many times you may wonder what exactly is taking all the time, or you just
59 want to know the amount of milliseconds between two points in a transfer. For
60 those, and other similar situations, the
61 [`--trace-time`](https://curl.se/docs/manpage.html#--trace-time) option
62 is what you need. It'll prepend the time to each trace output line:
63
64    curl --trace-ascii d.txt --trace-time http://example.com/
65
66## See the Response
67
68 By default curl sends the response to stdout. You need to redirect it
69 somewhere to avoid that, most often that is done with ` -o` or `-O`.
70
71# URL
72
73## Spec
74
75 The Uniform Resource Locator format is how you specify the address of a
76 particular resource on the Internet. You know these, you've seen URLs like
77 https://curl.se or https://yourbank.com a million times. RFC 3986 is the
78 canonical spec. And yeah, the formal name is not URL, it is URI.
79
80## Host
81
82 The host name is usually resolved using DNS or your /etc/hosts file to an IP
83 address and that's what curl will communicate with. Alternatively you specify
84 the IP address directly in the URL instead of a name.
85
86 For development and other trying out situations, you can point to a different
87 IP address for a host name than what would otherwise be used, by using curl's
88 [`--resolve`](https://curl.se/docs/manpage.html#--resolve) option:
89
90    curl --resolve www.example.org:80:127.0.0.1 http://www.example.org/
91
92## Port number
93
94 Each protocol curl supports operates on a default port number, be it over TCP
95 or in some cases UDP. Normally you don't have to take that into
96 consideration, but at times you run test servers on other ports or
97 similar. Then you can specify the port number in the URL with a colon and a
98 number immediately following the host name. Like when doing HTTP to port
99 1234:
100
101    curl http://www.example.org:1234/
102
103 The port number you specify in the URL is the number that the server uses to
104 offer its services. Sometimes you may use a proxy, and then you may
105 need to specify that proxy's port number separately from what curl needs to
106 connect to the server. Like when using a HTTP proxy on port 4321:
107
108    curl --proxy http://proxy.example.org:4321 http://remote.example.org/
109
110## User name and password
111
112 Some services are setup to require HTTP authentication and then you need to
113 provide name and password which is then transferred to the remote site in
114 various ways depending on the exact authentication protocol used.
115
116 You can opt to either insert the user and password in the URL or you can
117 provide them separately:
118
119    curl http://user:password@example.org/
120
121 or
122
123    curl -u user:password http://example.org/
124
125 You need to pay attention that this kind of HTTP authentication is not what
126 is usually done and requested by user-oriented websites these days. They tend
127 to use forms and cookies instead.
128
129## Path part
130
131 The path part is just sent off to the server to request that it sends back
132 the associated response. The path is what is to the right side of the slash
133 that follows the host name and possibly port number.
134
135# Fetch a page
136
137## GET
138
139 The simplest and most common request/operation made using HTTP is to GET a
140 URL. The URL could itself refer to a web page, an image or a file. The client
141 issues a GET request to the server and receives the document it asked for.
142 If you issue the command line
143
144    curl https://curl.se
145
146 you get a web page returned in your terminal window. The entire HTML document
147 that that URL holds.
148
149 All HTTP replies contain a set of response headers that are normally hidden,
150 use curl's [`--include`](https://curl.se/docs/manpage.html#-i) (`-i`)
151 option to display them as well as the rest of the document.
152
153## HEAD
154
155 You can ask the remote server for ONLY the headers by using the
156 [`--head`](https://curl.se/docs/manpage.html#-I) (`-I`) option which
157 will make curl issue a HEAD request. In some special cases servers deny the
158 HEAD method while others still work, which is a particular kind of annoyance.
159
160 The HEAD method is defined and made so that the server returns the headers
161 exactly the way it would do for a GET, but without a body. It means that you
162 may see a `Content-Length:` in the response headers, but there must not be an
163 actual body in the HEAD response.
164
165## Multiple URLs in a single command line
166
167 A single curl command line may involve one or many URLs. The most common case
168 is probably to just use one, but you can specify any amount of URLs. Yes
169 any. No limits. You'll then get requests repeated over and over for all the
170 given URLs.
171
172 Example, send two GETs:
173
174    curl http://url1.example.com http://url2.example.com
175
176 If you use [`--data`](https://curl.se/docs/manpage.html#-d) to POST to
177 the URL, using multiple URLs means that you send that same POST to all the
178 given URLs.
179
180 Example, send two POSTs:
181
182    curl --data name=curl http://url1.example.com http://url2.example.com
183
184
185## Multiple HTTP methods in a single command line
186
187 Sometimes you need to operate on several URLs in a single command line and do
188 different HTTP methods on each. For this, you'll enjoy the
189 [`--next`](https://curl.se/docs/manpage.html#-:) option. It is basically
190 a separator that separates a bunch of options from the next. All the URLs
191 before `--next` will get the same method and will get all the POST data
192 merged into one.
193
194 When curl reaches the `--next` on the command line, it'll sort of reset the
195 method and the POST data and allow a new set.
196
197 Perhaps this is best shown with a few examples. To send first a HEAD and then
198 a GET:
199
200    curl -I http://example.com --next http://example.com
201
202 To first send a POST and then a GET:
203
204    curl -d score=10 http://example.com/post.cgi --next http://example.com/results.html
205
206# HTML forms
207
208## Forms explained
209
210 Forms are the general way a website can present a HTML page with fields for
211 the user to enter data in, and then press some kind of 'OK' or 'Submit'
212 button to get that data sent to the server. The server then typically uses
213 the posted data to decide how to act. Like using the entered words to search
214 in a database, or to add the info in a bug tracking system, display the
215 entered address on a map or using the info as a login-prompt verifying that
216 the user is allowed to see what it is about to see.
217
218 Of course there has to be some kind of program on the server end to receive
219 the data you send. You cannot just invent something out of the air.
220
221## GET
222
223 A GET-form uses the method GET, as specified in HTML like:
224
225```html
226<form method="GET" action="junk.cgi">
227  <input type=text name="birthyear">
228  <input type=submit name=press value="OK">
229</form>
230```
231
232 In your favorite browser, this form will appear with a text box to fill in
233 and a press-button labeled "OK". If you fill in '1905' and press the OK
234 button, your browser will then create a new URL to get for you. The URL will
235 get `junk.cgi?birthyear=1905&press=OK` appended to the path part of the
236 previous URL.
237
238 If the original form was seen on the page `www.example.com/when/birth.html`,
239 the second page you'll get will become
240 `www.example.com/when/junk.cgi?birthyear=1905&press=OK`.
241
242 Most search engines work this way.
243
244 To make curl do the GET form post for you, just enter the expected created
245 URL:
246
247    curl "http://www.example.com/when/junk.cgi?birthyear=1905&press=OK"
248
249## POST
250
251 The GET method makes all input field names get displayed in the URL field of
252 your browser. That's generally a good thing when you want to be able to
253 bookmark that page with your given data, but it is an obvious disadvantage if
254 you entered secret information in one of the fields or if there are a large
255 amount of fields creating a very long and unreadable URL.
256
257 The HTTP protocol then offers the POST method. This way the client sends the
258 data separated from the URL and thus you won't see any of it in the URL
259 address field.
260
261 The form would look very similar to the previous one:
262
263```html
264<form method="POST" action="junk.cgi">
265  <input type=text name="birthyear">
266  <input type=submit name=press value=" OK ">
267</form>
268```
269
270 And to use curl to post this form with the same data filled in as before, we
271 could do it like:
272
273    curl --data "birthyear=1905&press=%20OK%20" http://www.example.com/when.cgi
274
275 This kind of POST will use the Content-Type
276 `application/x-www-form-urlencoded` and is the most widely used POST kind.
277
278 The data you send to the server MUST already be properly encoded, curl will
279 not do that for you. For example, if you want the data to contain a space,
280 you need to replace that space with `%20`, etc. Failing to comply with this will
281 most likely cause your data to be received wrongly and messed up.
282
283 Recent curl versions can in fact url-encode POST data for you, like this:
284
285    curl --data-urlencode "name=I am Daniel" http://www.example.com
286
287 If you repeat `--data` several times on the command line, curl will
288 concatenate all the given data pieces - and put a `&` symbol between each
289 data segment.
290
291## File Upload POST
292
293 Back in late 1995 they defined an additional way to post data over HTTP. It
294 is documented in the RFC 1867, why this method sometimes is referred to as
295 RFC1867-posting.
296
297 This method is mainly designed to better support file uploads. A form that
298 allows a user to upload a file could be written like this in HTML:
299
300```html
301<form method="POST" enctype='multipart/form-data' action="upload.cgi">
302  <input type=file name=upload>
303  <input type=submit name=press value="OK">
304</form>
305```
306
307 This clearly shows that the Content-Type about to be sent is
308 `multipart/form-data`.
309
310 To post to a form like this with curl, you enter a command line like:
311
312    curl --form upload=@localfilename --form press=OK [URL]
313
314## Hidden Fields
315
316 A very common way for HTML based applications to pass state information
317 between pages is to add hidden fields to the forms. Hidden fields are already
318 filled in, they aren't displayed to the user and they get passed along just
319 as all the other fields.
320
321 A similar example form with one visible field, one hidden field and one
322 submit button could look like:
323
324```html
325<form method="POST" action="foobar.cgi">
326  <input type=text name="birthyear">
327  <input type=hidden name="person" value="daniel">
328  <input type=submit name="press" value="OK">
329</form>
330```
331
332 To POST this with curl, you won't have to think about if the fields are
333 hidden or not. To curl they're all the same:
334
335    curl --data "birthyear=1905&press=OK&person=daniel" [URL]
336
337## Figure Out What A POST Looks Like
338
339 When you're about fill in a form and send to a server by using curl instead
340 of a browser, you're of course very interested in sending a POST exactly the
341 way your browser does.
342
343 An easy way to get to see this, is to save the HTML page with the form on
344 your local disk, modify the 'method' to a GET, and press the submit button
345 (you could also change the action URL if you want to).
346
347 You will then clearly see the data get appended to the URL, separated with a
348 `?`-letter as GET forms are supposed to.
349
350# HTTP upload
351
352## PUT
353
354 Perhaps the best way to upload data to a HTTP server is to use PUT. Then
355 again, this of course requires that someone put a program or script on the
356 server end that knows how to receive a HTTP PUT stream.
357
358 Put a file to a HTTP server with curl:
359
360    curl --upload-file uploadfile http://www.example.com/receive.cgi
361
362# HTTP Authentication
363
364## Basic Authentication
365
366 HTTP Authentication is the ability to tell the server your username and
367 password so that it can verify that you're allowed to do the request you're
368 doing. The Basic authentication used in HTTP (which is the type curl uses by
369 default) is **plain text** based, which means it sends username and password
370 only slightly obfuscated, but still fully readable by anyone that sniffs on
371 the network between you and the remote server.
372
373 To tell curl to use a user and password for authentication:
374
375    curl --user name:password http://www.example.com
376
377## Other Authentication
378
379 The site might require a different authentication method (check the headers
380 returned by the server), and then
381 [`--ntlm`](https://curl.se/docs/manpage.html#--ntlm),
382 [`--digest`](https://curl.se/docs/manpage.html#--digest),
383 [`--negotiate`](https://curl.se/docs/manpage.html#--negotiate) or even
384 [`--anyauth`](https://curl.se/docs/manpage.html#--anyauth) might be
385 options that suit you.
386
387## Proxy Authentication
388
389 Sometimes your HTTP access is only available through the use of a HTTP
390 proxy. This seems to be especially common at various companies. A HTTP proxy
391 may require its own user and password to allow the client to get through to
392 the Internet. To specify those with curl, run something like:
393
394    curl --proxy-user proxyuser:proxypassword curl.se
395
396 If your proxy requires the authentication to be done using the NTLM method,
397 use [`--proxy-ntlm`](https://curl.se/docs/manpage.html#--proxy-ntlm), if
398 it requires Digest use
399 [`--proxy-digest`](https://curl.se/docs/manpage.html#--proxy-digest).
400
401 If you use any one of these user+password options but leave out the password
402 part, curl will prompt for the password interactively.
403
404## Hiding credentials
405
406 Do note that when a program is run, its parameters might be possible to see
407 when listing the running processes of the system. Thus, other users may be
408 able to watch your passwords if you pass them as plain command line
409 options. There are ways to circumvent this.
410
411 It is worth noting that while this is how HTTP Authentication works, very
412 many websites will not use this concept when they provide logins etc. See the
413 Web Login chapter further below for more details on that.
414
415# More HTTP Headers
416
417## Referer
418
419 A HTTP request may include a 'referer' field (yes it is misspelled), which
420 can be used to tell from which URL the client got to this particular
421 resource. Some programs/scripts check the referer field of requests to verify
422 that this wasn't arriving from an external site or an unknown page. While
423 this is a stupid way to check something so easily forged, many scripts still
424 do it. Using curl, you can put anything you want in the referer-field and
425 thus more easily be able to fool the server into serving your request.
426
427 Use curl to set the referer field with:
428
429    curl --referer http://www.example.come http://www.example.com
430
431## User Agent
432
433 Very similar to the referer field, all HTTP requests may set the User-Agent
434 field. It names what user agent (client) that is being used. Many
435 applications use this information to decide how to display pages. Silly web
436 programmers try to make different pages for users of different browsers to
437 make them look the best possible for their particular browsers. They usually
438 also do different kinds of javascript, vbscript etc.
439
440 At times, you will see that getting a page with curl will not return the same
441 page that you see when getting the page with your browser. Then you know it
442 is time to set the User Agent field to fool the server into thinking you're
443 one of those browsers.
444
445 To make curl look like Internet Explorer 5 on a Windows 2000 box:
446
447    curl --user-agent "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)" [URL]
448
449 Or why not look like you're using Netscape 4.73 on an old Linux box:
450
451    curl --user-agent "Mozilla/4.73 [en] (X11; U; Linux 2.2.15 i686)" [URL]
452
453## Redirects
454
455## Location header
456
457 When a resource is requested from a server, the reply from the server may
458 include a hint about where the browser should go next to find this page, or a
459 new page keeping newly generated output. The header that tells the browser to
460 redirect is `Location:`.
461
462 Curl does not follow `Location:` headers by default, but will simply display
463 such pages in the same manner it displays all HTTP replies. It does however
464 feature an option that will make it attempt to follow the `Location:`
465 pointers.
466
467 To tell curl to follow a Location:
468
469    curl --location http://www.example.com
470
471 If you use curl to POST to a site that immediately redirects you to another
472 page, you can safely use
473 [`--location`](https://curl.se/docs/manpage.html#-L) (`-L`) and
474 `--data`/`--form` together. curl will only use POST in the first request, and
475 then revert to GET in the following operations.
476
477## Other redirects
478
479 Browser typically support at least two other ways of redirects that curl
480 doesn't: first the html may contain a meta refresh tag that asks the browser
481 to load a specific URL after a set number of seconds, or it may use
482 javascript to do it.
483
484# Cookies
485
486## Cookie Basics
487
488 The way the web browsers do "client side state control" is by using
489 cookies. Cookies are just names with associated contents. The cookies are
490 sent to the client by the server. The server tells the client for what path
491 and host name it wants the cookie sent back, and it also sends an expiration
492 date and a few more properties.
493
494 When a client communicates with a server with a name and path as previously
495 specified in a received cookie, the client sends back the cookies and their
496 contents to the server, unless of course they are expired.
497
498 Many applications and servers use this method to connect a series of requests
499 into a single logical session. To be able to use curl in such occasions, we
500 must be able to record and send back cookies the way the web application
501 expects them. The same way browsers deal with them.
502
503## Cookie options
504
505 The simplest way to send a few cookies to the server when getting a page with
506 curl is to add them on the command line like:
507
508    curl --cookie "name=Daniel" http://www.example.com
509
510 Cookies are sent as common HTTP headers. This is practical as it allows curl
511 to record cookies simply by recording headers. Record cookies with curl by
512 using the [`--dump-header`](https://curl.se/docs/manpage.html#-D) (`-D`)
513 option like:
514
515    curl --dump-header headers_and_cookies http://www.example.com
516
517 (Take note that the
518 [`--cookie-jar`](https://curl.se/docs/manpage.html#-c) option described
519 below is a better way to store cookies.)
520
521 Curl has a full blown cookie parsing engine built-in that comes in use if you
522 want to reconnect to a server and use cookies that were stored from a
523 previous connection (or hand-crafted manually to fool the server into
524 believing you had a previous connection). To use previously stored cookies,
525 you run curl like:
526
527    curl --cookie stored_cookies_in_file http://www.example.com
528
529 Curl's "cookie engine" gets enabled when you use the
530 [`--cookie`](https://curl.se/docs/manpage.html#-b) option. If you only
531 want curl to understand received cookies, use `--cookie` with a file that
532 doesn't exist. Example, if you want to let curl understand cookies from a
533 page and follow a location (and thus possibly send back cookies it received),
534 you can invoke it like:
535
536    curl --cookie nada --location http://www.example.com
537
538 Curl has the ability to read and write cookie files that use the same file
539 format that Netscape and Mozilla once used. It is a convenient way to share
540 cookies between scripts or invokes. The `--cookie` (`-b`) switch
541 automatically detects if a given file is such a cookie file and parses it,
542 and by using the `--cookie-jar` (`-c`) option you'll make curl write a new
543 cookie file at the end of an operation:
544
545    curl --cookie cookies.txt --cookie-jar newcookies.txt \
546    http://www.example.com
547
548# HTTPS
549
550## HTTPS is HTTP secure
551
552 There are a few ways to do secure HTTP transfers. By far the most common
553 protocol for doing this is what is generally known as HTTPS, HTTP over
554 SSL. SSL encrypts all the data that is sent and received over the network and
555 thus makes it harder for attackers to spy on sensitive information.
556
557 SSL (or TLS as the latest version of the standard is called) offers a
558 truckload of advanced features to allow all those encryptions and key
559 infrastructure mechanisms encrypted HTTP requires.
560
561 Curl supports encrypted fetches when built to use a TLS library and it can be
562 built to use one out of a fairly large set of libraries - `curl -V` will show
563 which one your curl was built to use (if any!). To get a page from a HTTPS
564 server, simply run curl like:
565
566    curl https://secure.example.com
567
568## Certificates
569
570 In the HTTPS world, you use certificates to validate that you are the one
571 you claim to be, as an addition to normal passwords. Curl supports client-
572 side certificates. All certificates are locked with a pass phrase, which you
573 need to enter before the certificate can be used by curl. The pass phrase
574 can be specified on the command line or if not, entered interactively when
575 curl queries for it. Use a certificate with curl on a HTTPS server like:
576
577    curl --cert mycert.pem https://secure.example.com
578
579 curl also tries to verify that the server is who it claims to be, by
580 verifying the server's certificate against a locally stored CA cert
581 bundle. Failing the verification will cause curl to deny the connection. You
582 must then use [`--insecure`](https://curl.se/docs/manpage.html#-k)
583 (`-k`) in case you want to tell curl to ignore that the server can't be
584 verified.
585
586 More about server certificate verification and ca cert bundles can be read in
587 the [SSLCERTS document](https://curl.se/docs/sslcerts.html).
588
589 At times you may end up with your own CA cert store and then you can tell
590 curl to use that to verify the server's certificate:
591
592    curl --cacert ca-bundle.pem https://example.com/
593
594# Custom Request Elements
595
596## Modify method and headers
597
598 Doing fancy stuff, you may need to add or change elements of a single curl
599 request.
600
601 For example, you can change the POST request to a PROPFIND and send the data
602 as `Content-Type: text/xml` (instead of the default Content-Type) like this:
603
604    curl --data "<xml>" --header "Content-Type: text/xml" \
605      --request PROPFIND example.com
606
607 You can delete a default header by providing one without content. Like you
608 can ruin the request by chopping off the Host: header:
609
610    curl --header "Host:" http://www.example.com
611
612 You can add headers the same way. Your server may want a `Destination:`
613 header, and you can add it:
614
615    curl --header "Destination: http://nowhere" http://example.com
616
617## More on changed methods
618
619 It should be noted that curl selects which methods to use on its own
620 depending on what action to ask for. `-d` will do POST, `-I` will do HEAD and
621 so on. If you use the
622 [`--request`](https://curl.se/docs/manpage.html#-X) / `-X` option you
623 can change the method keyword curl selects, but you will not modify curl's
624 behavior. This means that if you for example use -d "data" to do a POST, you
625 can modify the method to a `PROPFIND` with `-X` and curl will still think it
626 sends a POST . You can change the normal GET to a POST method by simply
627 adding `-X POST` in a command line like:
628
629    curl -X POST http://example.org/
630
631 ... but curl will still think and act as if it sent a GET so it won't send
632 any request body etc.
633
634# Web Login
635
636## Some login tricks
637
638 While not strictly just HTTP related, it still causes a lot of people
639 problems so here's the executive run-down of how the vast majority of all
640 login forms work and how to login to them using curl.
641
642 It can also be noted that to do this properly in an automated fashion, you
643 will most certainly need to script things and do multiple curl invokes etc.
644
645 First, servers mostly use cookies to track the logged-in status of the
646 client, so you will need to capture the cookies you receive in the
647 responses. Then, many sites also set a special cookie on the login page (to
648 make sure you got there through their login page) so you should make a habit
649 of first getting the login-form page to capture the cookies set there.
650
651 Some web-based login systems feature various amounts of javascript, and
652 sometimes they use such code to set or modify cookie contents. Possibly they
653 do that to prevent programmed logins, like this manual describes how to...
654 Anyway, if reading the code isn't enough to let you repeat the behavior
655 manually, capturing the HTTP requests done by your browsers and analyzing the
656 sent cookies is usually a working method to work out how to shortcut the
657 javascript need.
658
659 In the actual `<form>` tag for the login, lots of sites fill-in
660 random/session or otherwise secretly generated hidden tags and you may need
661 to first capture the HTML code for the login form and extract all the hidden
662 fields to be able to do a proper login POST. Remember that the contents need
663 to be URL encoded when sent in a normal POST.
664
665# Debug
666
667## Some debug tricks
668
669 Many times when you run curl on a site, you'll notice that the site doesn't
670 seem to respond the same way to your curl requests as it does to your
671 browser's.
672
673 Then you need to start making your curl requests more similar to your
674 browser's requests:
675
676 - Use the `--trace-ascii` option to store fully detailed logs of the requests
677   for easier analyzing and better understanding
678
679 - Make sure you check for and use cookies when needed (both reading with
680   `--cookie` and writing with `--cookie-jar`)
681
682 - Set user-agent (with [`-A`](https://curl.se/docs/manpage.html#-A)) to
683   one like a recent popular browser does
684
685 - Set referer (with [`-E`](https://curl.se/docs/manpage.html#-E)) like
686   it is set by the browser
687
688 - If you use POST, make sure you send all the fields and in the same order as
689   the browser does it.
690
691## Check what the browsers do
692
693 A very good helper to make sure you do this right, is the web browsers'
694 developers tools that let you view all headers you send and receive (even
695 when using HTTPS).
696
697 A more raw approach is to capture the HTTP traffic on the network with tools
698 such as Wireshark or tcpdump and check what headers that were sent and
699 received by the browser. (HTTPS forces you to use `SSLKEYLOGFILE` to do
700 that.)
701