~ubuntu-branches/ubuntu/warty/curl/warty-security

« back to all changes in this revision

Viewing changes to docs/TheArtOfHttpScripting

  • Committer: Bazaar Package Importer
  • Author(s): Domenico Andreoli
  • Date: 2004-06-04 19:09:25 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040604190925-wy048bp31320r2z6
Tags: 7.12.0.is.7.11.2-1
* Reverted to version 7.11.2 (closes: #252348).
* Disabled support for libidn (closes: #252367). This is to leave
  curl in unstable as much similar as possible to the one in testing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
Online:  http://curl.haxx.se/docs/httpscripting.shtml
2
2
Author:  Daniel Stenberg <daniel@haxx.se>
3
 
Date:    October 31, 2001
4
 
Version: 0.5
 
3
Date:    November 6, 2001
 
4
Version: 0.6
5
5
 
6
6
                The Art Of Scripting HTTP Requests Using Curl
7
7
                =============================================
65
65
 
66
66
 All HTTP replies contain a set of headers that are normally hidden, use
67
67
 curl's -i option to display them as well as the rest of the document. You can
68
 
 also ask the remote server for ONLY the headers by using the -I option.
 
68
 also ask the remote server for ONLY the headers by using the -I option (which
 
69
 will make curl issue a HEAD request).
69
70
 
70
71
4. Forms
71
72
 
122
123
 
123
124
        <form method="POST" action="junk.cgi">
124
125
          <input type=text name="birthyear">
125
 
          <input type=submit name=press value="OK">
 
126
          <input type=submit name=press value=" OK ">
126
127
        </form>
127
128
 
128
129
  And to use curl to post this form with the same data filled in as before, we
129
130
  could do it like:
130
131
 
131
 
        curl -d "birthyear=1905&press=OK" www.hotmail.com/when/junk.cgi
 
132
        curl -d "birthyear=1905&press=%20OK%20" www.hotmail.com/when/junk.cgi
132
133
 
133
134
  This kind of POST will use the Content-Type
134
135
  application/x-www-form-urlencoded and is the most widely used POST kind.
135
136
 
 
137
  The data you send to the server MUST already be properly encoded, curl will
 
138
  not do that for you. For example, if you want the data to contain a space,
 
139
  you need to replace that space with %20 etc. Failing to comply with this
 
140
  will most likely cause your data to be received wrongly and messed up.
 
141
 
136
142
 4.3 FILE UPLOAD POST
137
143
 
138
144
  Back in late 1995 they defined a new way to post data over HTTP. It was
202
208
 
203
209
 Authentication is the ability to tell the server your username and password
204
210
 so that it can verify that you're allowed to do the request you're doing. The
205
 
 basic authentication used in HTTP is *plain* *text* based, which means it
206
 
 sends username and password only slightly obfuscated, but still fully
207
 
 readable by anyone that sniffs on the network between you and the remote
208
 
 server.
 
211
 Basic authentication used in HTTP (which is the type curl uses by default) is
 
212
 *plain* *text* based, which means it sends username and password only
 
213
 slightly obfuscated, but still fully readable by anyone that sniffs on the
 
214
 network between you and the remote server.
209
215
 
210
216
 To tell curl to use a user and password for authentication:
211
217
 
212
218
        curl -u name:password www.secrets.com
 
219
 
 
220
 The site might require a different authentication method (check the headers
 
221
 returned by the server), and then --ntlm, --digest, --negotiate or even
 
222
 --anyauth might be options that suit you.
213
223
 
214
224
 Sometimes your HTTP access is only available through the use of a HTTP
215
225
 proxy. This seems to be especially common at various companies. A HTTP proxy
218
228
 
219
229
        curl -U proxyuser:proxypassword curl.haxx.se
220
230
 
 
231
 If your proxy requires the authentication to be done using the NTLM method,
 
232
 use --proxy-ntlm.
 
233
 
221
234
 If you use any one these user+password options but leave out the password
222
235
 part, curl will prompt for the password interactively.
223
236
 
309
322
 
310
323
        curl -D headers_and_cookies www.cookiesite.com
311
324
 
 
325
 (Take note that the -c option described below is a better way to store
 
326
 cookies.)
 
327
 
312
328
 Curl has a full blown cookie parsing engine built-in that comes to use if you
313
329
 want to reconnect to a server and use cookies that were stored from a
314
330
 previous connection (or handicrafted manually to fool the server into
362
378
 
363
379
        curl -E mycert.pem https://that.secure.server.com
364
380
 
 
381
  curl also tries to verify that the server is who it claims to be, by
 
382
  verifying the server's certificate against a CA cert bundle. Failing the
 
383
  verification will cause curl to deny the connection. You must then use -k in
 
384
  case you want to tell curl to ignore that the server can't be verified.
 
385
 
365
386
12. REFERENCES
366
387
 
367
388
 RFC 2616 is a must to read if you want in-depth understanding of the HTTP