FAQ 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  1. Updated: Nov 7, 2009 (http://curl.haxx.se/docs/faq.html)
  2. _ _ ____ _
  3. ___| | | | _ \| |
  4. / __| | | | |_) | |
  5. | (__| |_| | _ <| |___
  6. \___|\___/|_| \_\_____|
  7. FAQ
  8. 1. Philosophy
  9. 1.1 What is cURL?
  10. 1.2 What is libcurl?
  11. 1.3 What is curl not?
  12. 1.4 When will you make curl do XXXX ?
  13. 1.5 Who makes curl?
  14. 1.6 What do you get for making curl?
  15. 1.7 What about CURL from curl.com?
  16. 1.8 I have a problem who do I mail?
  17. 1.9 Where do I buy commercial support for curl?
  18. 1.10 How many are using curl?
  19. 1.11 Why don't you update ca-bundle.crt
  20. 1.12 I have a problem who can I chat with?
  21. 2. Install Related Problems
  22. 2.1 configure doesn't find OpenSSL even when it is installed
  23. 2.1.1 native linker doesn't find OpenSSL
  24. 2.1.2 only the libssl lib is missing
  25. 2.2 Does curl work/build with other SSL libraries?
  26. 2.3 Where can I find a copy of LIBEAY32.DLL?
  27. 2.4 Does curl support SOCKS (RFC 1928) ?
  28. 3. Usage Problems
  29. 3.1 curl: (1) SSL is disabled, https: not supported
  30. 3.2 How do I tell curl to resume a transfer?
  31. 3.3 Why doesn't my posting using -F work?
  32. 3.4 How do I tell curl to run custom FTP commands?
  33. 3.5 How can I disable the Pragma: nocache header?
  34. 3.6 Does curl support ASP, XML, XHTML or HTML version Y?
  35. 3.7 Can I use curl to delete/rename a file through FTP?
  36. 3.8 How do I tell curl to follow HTTP redirects?
  37. 3.9 How do I use curl in my favorite programming language?
  38. 3.10 What about SOAP, WebDAV, XML-RPC or similar protocols over HTTP?
  39. 3.11 How do I POST with a different Content-Type?
  40. 3.12 Why do FTP specific features over HTTP proxy fail?
  41. 3.13 Why does my single/double quotes fail?
  42. 3.14 Does curl support Javascript or PAC (automated proxy config)?
  43. 3.15 Can I do recursive fetches with curl?
  44. 3.16 What certificates do I need when I use SSL?
  45. 3.17 How do I list the root dir of an FTP server?
  46. 3.18 Can I use curl to send a POST/PUT and not wait for a response?
  47. 4. Running Problems
  48. 4.1 Problems connecting to SSL servers.
  49. 4.2 Why do I get problems when I use & or % in the URL?
  50. 4.3 How can I use {, }, [ or ] to specify multiple URLs?
  51. 4.4 Why do I get downloaded data even though the web page doesn't exist?
  52. 4.5 Why do I get return code XXX from a HTTP server?
  53. 4.5.1 "400 Bad Request"
  54. 4.5.2 "401 Unauthorized"
  55. 4.5.3 "403 Forbidden"
  56. 4.5.4 "404 Not Found"
  57. 4.5.5 "405 Method Not Allowed"
  58. 4.5.6 "301 Moved Permanently"
  59. 4.6 Can you tell me what error code 142 means?
  60. 4.7 How do I keep user names and passwords secret in Curl command lines?
  61. 4.8 I found a bug!
  62. 4.9 Curl can't authenticate to the server that requires NTLM?
  63. 4.10 My HTTP request using HEAD, PUT or DELETE doesn't work!
  64. 4.11 Why does my HTTP range requests return the full document?
  65. 4.12 Why do I get "certificate verify failed" ?
  66. 4.13 Why is curl -R on Windows one hour off?
  67. 4.14 Redirects work in browser but not with curl!
  68. 4.15 FTPS doesn't work
  69. 4.16 My HTTP POST or PUT requests are slow!
  70. 4.17 Non-functional connect timeouts on Windows
  71. 4.18 file:// URLs containing drive letters (Windows, NetWare)
  72. 5. libcurl Issues
  73. 5.1 Is libcurl thread-safe?
  74. 5.2 How can I receive all data into a large memory chunk?
  75. 5.3 How do I fetch multiple files with libcurl?
  76. 5.4 Does libcurl do Winsock initing on win32 systems?
  77. 5.5 Does CURLOPT_WRITEDATA and CURLOPT_READDATA work on win32 ?
  78. 5.6 What about Keep-Alive or persistent connections?
  79. 5.7 Link errors when building libcurl on Windows!
  80. 5.8 libcurl.so.3: open failed: No such file or directory
  81. 5.9 How does libcurl resolve host names?
  82. 5.10 How do I prevent libcurl from writing the response to stdout?
  83. 5.11 How do I make libcurl not receive the whole HTTP response?
  84. 5.12 Can I make libcurl fake or hide my real IP address?
  85. 5.13 How do I stop an ongoing transfer?
  86. 5.14 Using C++ non-static functions for callbacks?
  87. 5.15 How do I get an FTP directory listing?
  88. 6. License Issues
  89. 6.1 I have a GPL program, can I use the libcurl library?
  90. 6.2 I have a closed-source program, can I use the libcurl library?
  91. 6.3 I have a BSD licensed program, can I use the libcurl library?
  92. 6.4 I have a program that uses LGPL libraries, can I use libcurl?
  93. 6.5 Can I modify curl/libcurl for my program and keep the changes secret?
  94. 6.6 Can you please change the curl/libcurl license to XXXX?
  95. 6.7 What are my obligations when using libcurl in my commercial apps?
  96. 7. PHP/CURL Issues
  97. 7.1 What is PHP/CURL?
  98. 7.2 Who write PHP/CURL?
  99. 7.3 Can I perform multiple requests using the same handle?
  100. ==============================================================================
  101. 1. Philosophy
  102. 1.1 What is cURL?
  103. cURL is the name of the project. The name is a play on 'Client for URLs',
  104. originally with URL spelled in uppercase to make it obvious it deals with
  105. URLs. The fact it can also be pronounced 'see URL' also helped, it works as
  106. an abbreviation for "Client URL Request Library" or why not the recursive
  107. version: "Curl URL Request Library".
  108. The cURL project produces two products:
  109. libcurl
  110. A free and easy-to-use client-side URL transfer library, supporting FTP,
  111. FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, FILE, LDAP and LDAPS.
  112. libcurl supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading,
  113. kerberos, HTTP form based upload, proxies, cookies, user+password
  114. authentication, file transfer resume, http proxy tunneling and more!
  115. libcurl is highly portable, it builds and works identically on numerous
  116. platforms, including Solaris, NetBSD, FreeBSD, OpenBSD, Darwin, HPUX,
  117. IRIX, AIX, Tru64, Linux, UnixWare, HURD, Windows, Amiga, OS/2, BeOs, Mac
  118. OS X, Ultrix, QNX, OpenVMS, RISC OS, Novell NetWare, DOS, Symbian, OSF,
  119. Android, Minix, IBM TPF and more...
  120. libcurl is free, thread-safe, IPv6 compatible, feature rich, well
  121. supported and fast.
  122. curl
  123. A command line tool for getting or sending files using URL syntax.
  124. Since curl uses libcurl, it supports a range of common Internet protocols,
  125. currently including HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP, LDAP, LDAPS,
  126. DICT, TELNET and FILE.
  127. We pronounce curl and cURL with an initial k sound: [kurl].
  128. There are numerous sub-projects and related projects that also use the word
  129. curl in the project names in various combinations, but you should take
  130. notice that this FAQ is directed at the command-line tool named curl (and
  131. libcurl the library), and may therefore not be valid for other curl-related
  132. projects. (There is however a small section for the PHP/CURL in this FAQ.)
  133. 1.2 What is libcurl?
  134. libcurl is a reliable and portable library which provides you with an easy
  135. interface to a range of common Internet protocols.
  136. You can use libcurl for free in your application, be it open source,
  137. commercial or closed-source.
  138. libcurl is most probably the most portable, most powerful and most often
  139. used C-based multi-platform file transfer library on this planet - be it
  140. open source or commercial.
  141. 1.3 What is curl not?
  142. Curl is not a wget clone. That is a common misconception. Never, during
  143. curl's development, have we intended curl to replace wget or compete on its
  144. market. Curl is targeted at single-shot file transfers.
  145. Curl is not a web site mirroring program. If you want to use curl to mirror
  146. something: fine, go ahead and write a script that wraps around curl to make
  147. it reality (like curlmirror.pl does).
  148. Curl is not an FTP site mirroring program. Sure, get and send FTP with curl
  149. but if you want systematic and sequential behavior you should write a
  150. script (or write a new program that interfaces libcurl) and do it.
  151. Curl is not a PHP tool, even though it works perfectly well when used from
  152. or with PHP (when using the PHP/CURL module).
  153. Curl is not a program for a single operating system. Curl exists, compiles,
  154. builds and runs under a wide range of operating systems, including all
  155. modern Unixes (and a bunch of older ones too), Windows, Amiga, BeOS, OS/2,
  156. OS X, QNX etc.
  157. 1.4 When will you make curl do XXXX ?
  158. We love suggestions of what to change in order to make curl and libcurl
  159. better. We do however believe in a few rules when it comes to the future of
  160. curl:
  161. * Curl -- the command line tool -- is to remain a non-graphical command line
  162. tool. If you want GUIs or fancy scripting capabilities, you should look
  163. for another tool that uses libcurl.
  164. * We do not add things to curl that other small and available tools already
  165. do very fine at the side. Curl's output is fine to pipe into another
  166. program or redirect to another file for the next program to interpret.
  167. * We focus on protocol related issues and improvements. If you wanna do more
  168. magic with the supported protocols than curl currently does, chances are
  169. big we will agree. If you wanna add more protocols, we may very well
  170. agree.
  171. * If you want someone else to make all the work while you wait for us to
  172. implement it for you, that is not a very friendly attitude. We spend a
  173. considerable time already on maintaining and developing curl. In order to
  174. get more out of us, you should consider trading in some of your time and
  175. efforts in return.
  176. * If you write the code, chances are bigger that it will get into curl
  177. faster.
  178. 1.5 Who makes curl?
  179. curl and libcurl are not made by any single individual. Daniel Stenberg is
  180. project leader and main developer, but other persons' submissions are
  181. important and crucial. Anyone can contribute and post their changes and
  182. improvements and have them inserted in the main sources (of course on the
  183. condition that developers agree on that the fixes are good).
  184. The full list of all contributors is found in the docs/THANKS file.
  185. curl is developed by a community, with Daniel at the wheel.
  186. 1.6 What do you get for making curl?
  187. Project cURL is entirely free and open. No person gets paid for developing
  188. (lib)curl on full or even part time. We do this voluntarily on our spare
  189. time. Occasionally companies pay individual developers to work on curl, but
  190. that's up to each company and developer. It is not controlled by nor
  191. supervised in any way by the project.
  192. We still get help from companies. Haxx provides web site, bandwidth, mailing
  193. lists, CVS server etc and sourceforge.net hosts project services we take
  194. advantage from, like the bug tracker. Also again, some companies have
  195. sponsored certain parts of the development in the past and I hope some will
  196. continue to do so in the future.
  197. If you want to support our project, consider a donation or a banner-program
  198. or even better: by helping us coding, documenting, testing etc.
  199. 1.7 What about CURL from curl.com?
  200. During the summer 2001, curl.com was busy advertising their client-side
  201. programming language for the web, named CURL.
  202. We are in no way associated with curl.com or their CURL programming
  203. language.
  204. Our project name curl has been in effective use since 1998. We were not the
  205. first computer related project to use the name "curl" and do not claim any
  206. first-hand rights to the name.
  207. We recognize that we will be living in parallel with curl.com and wish them
  208. every success.
  209. 1.8 I have a problem who do I mail?
  210. Please do not mail any single individual unless you really need to. Keep
  211. curl-related questions on a suitable mailing list. All available mailing
  212. lists are listed in the MANUAL document and online at
  213. http://curl.haxx.se/mail/
  214. Keeping curl-related questions and discussions on mailing lists allows
  215. others to join in and help, to share their ideas, contribute their
  216. suggestions and spread their wisdom. Keeping discussions on public mailing
  217. lists also allows for others to learn from this (both current and future
  218. users thanks to the web based archives of the mailing lists), thus saving us
  219. from having to repeat ourselves even more. Thanks for respecting this.
  220. If you have found or simply suspect a security problem in curl or libcurl,
  221. mail curl-security at haxx.se (closed list of receivers, mails are not
  222. disclosed) and tell. Then we can produce a fix in a timely manner before the
  223. flaw is announced to the world, thus lessen the impact the problem will have
  224. on existing users.
  225. 1.9 Where do I buy commercial support for curl?
  226. curl is fully open source. It means you can hire any skilled engineer to fix
  227. your curl-related problems.
  228. We list available alternatives on the curl web site:
  229. http://curl.haxx.se/support.html
  230. 1.10 How many are using curl?
  231. It is impossible to tell.
  232. We don't know how many users that knowingly have installed and use curl.
  233. We don't know how many users that use curl without knowing that they are in
  234. fact using it.
  235. We don't know how many users that downloaded or installed curl and then
  236. never use it.
  237. Some facts to use as input to the math:
  238. curl packages are downloaded from the curl.haxx.se and mirrors over a
  239. million times per year. curl is installed by default with most Linux
  240. distributions. curl is installed by default with Mac OS X. curl and libcurl
  241. as used by numerous applications that include libcurl binaries in their
  242. distribution packages (like Adobe Acrobat Reader and Google Earth).
  243. More than 90 known named companies use curl in commercial environments and
  244. products. More than 100 known named open source projects depend on
  245. (lib)curl.
  246. In a poll on the curl web site mid-2005, more than 50% of the 300+ answers
  247. estimated a user base of one million users or more.
  248. In March 2005, the "Linux Counter project" estimated a total Linux user base
  249. of some 29 millions, while Netcraft detected some 4 million "active" Linux
  250. based web servers. A guess is that a fair amount of these Linux
  251. installations have curl installed.
  252. All this taken together, there is no doubt that there are millions of
  253. (lib)curl users.
  254. http://curl.haxx.se/docs/companies.html
  255. http://curl.haxx.se/docs/programs.html
  256. http://curl.haxx.se/libcurl/using/apps.html
  257. http://counter.li.org/estimates.php
  258. http://news.netcraft.com/archives/2005/03/14/fedora_makes_rapid_progress.html
  259. 1.11 Why don't you update ca-bundle.crt
  260. The ca-bundle.crt file that used to be bundled with curl was very outdated
  261. (it being last modified year 2000 should tell) and must be replaced with a
  262. much more modern and up-to-date version by anyone who wants to verify peers
  263. anyway. It is no longer provided, the last curl release that shipped it was
  264. curl 7.18.0.
  265. In the cURL project we've decided not to attempt to keep this file updated
  266. (or even present anymore) since deciding what to add to a ca cert bundle is
  267. an undertaking we've not been ready to accept, and the one we can get from
  268. Mozilla is perfectly fine so there's no need to duplicate that work.
  269. Today, with many services performed over HTTPS, every operating system
  270. should come with a default ca cert bundle that can be deemed somewhat
  271. trustworthy and that collection (if reasonably updated) should be deemed to
  272. be a lot better than a private curl version.
  273. If you want the most recent collection of ca certs that Mozilla Firefox
  274. uses, we recommend that you extract the collection yourself from Mozilla
  275. Firefox (by running 'make ca-bundle), or by using our online service setup
  276. for this purpose: http://curl.haxx.se/docs/caextract.html
  277. 1.12 I have a problem who can I chat with?
  278. There's a bunch of friendly people hanging out in the #curl channel on the
  279. IRC network irc.freenode.net. If you're polite and nice, chances are big
  280. that you can get -- or provide -- help instantly.
  281. 2. Install Related Problems
  282. 2.1 configure doesn't find OpenSSL even when it is installed
  283. This may be because of several reasons.
  284. 2.1.1 native linker doesn't find openssl
  285. Affected platforms:
  286. Solaris (native cc compiler)
  287. HPUX (native cc compiler)
  288. SGI IRIX (native cc compiler)
  289. SCO UNIX (native cc compiler)
  290. When configuring curl, I specify --with-ssl. OpenSSL is installed in
  291. /usr/local/ssl Configure reports SSL in /usr/local/ssl, but fails to find
  292. CRYPTO_lock in -lcrypto
  293. Cause: The cc for this test places the -L/usr/local/ssl/lib AFTER
  294. -lcrypto, so ld can't find the library. This is due to a bug in the GNU
  295. autoconf tool.
  296. Workaround: Specifying "LDFLAGS=-L/usr/local/ssl/lib" in front of
  297. ./configure places the -L/usr/local/ssl/lib early enough in the command
  298. line to make things work
  299. 2.1.2 only the libssl lib is missing
  300. If all include files and the libcrypto lib is present, with only the
  301. libssl being missing according to configure, this is mostly likely because
  302. a few functions are left out from the libssl.
  303. If the function names missing include RSA or RSAREF you can be certain
  304. that this is because libssl requires the RSA and RSAREF libs to build.
  305. See the INSTALL file section that explains how to add those libs to
  306. configure. Make sure that you remove the config.cache file before you
  307. rerun configure with the new flags.
  308. 2.2 Does curl work/build with other SSL libraries?
  309. Curl has been written to use OpenSSL, GnuTLS, yassl or NSS, although there
  310. should not be many problems using a different library. If anyone does "port"
  311. curl to use a different SSL library, we are of course very interested in
  312. getting the patch!
  313. 2.3 Where can I find a copy of LIBEAY32.DLL?
  314. That is an OpenSSL binary built for Windows.
  315. Curl uses OpenSSL to do the SSL stuff. The LIBEAY32.DLL is what curl needs
  316. on a windows machine to do https://. Check out the curl web site to find
  317. accurate and up-to-date pointers to recent OpenSSL DLLs and other binary
  318. packages.
  319. 2.4 Does curl support SOCKS (RFC 1928) ?
  320. Yes, SOCKS 4 and 5 are supported.
  321. 3. Usage problems
  322. 3.1 curl: (1) SSL is disabled, https: not supported
  323. If you get this output when trying to get anything from a https:// server,
  324. it means that the configure script couldn't find all libs and include files
  325. it requires for SSL to work. If the configure script fails to find them,
  326. curl is simply built without SSL support.
  327. To get the https:// support into a curl that was previously built but that
  328. reports that https:// is not supported, you should dig through the document
  329. and logs and check out why the configure script doesn't find the SSL libs
  330. and/or include files.
  331. Also, check out the other paragraph in this FAQ labelled "configure doesn't
  332. find OpenSSL even when it is installed".
  333. 3.2 How do I tell curl to resume a transfer?
  334. Curl supports resumed transfers both ways on both FTP and HTTP.
  335. Try the -C option.
  336. 3.3 Why doesn't my posting using -F work?
  337. You can't simply use -F or -d at your choice. The web server that will
  338. receive your post assumes one of the formats. If the form you're trying to
  339. "fake" sets the type to 'multipart/form-data', then and only then you must
  340. use the -F type. In all the most common cases, you should use -d which then
  341. causes a posting with the type 'application/x-www-form-urlencoded'.
  342. This is described in some detail in the MANUAL and TheArtOfHttpScripting
  343. documents, and if you don't understand it the first time, read it again
  344. before you post questions about this to the mailing list. Also, try reading
  345. through the mailing list archives for old postings and questions regarding
  346. this.
  347. 3.4 How do I tell curl to run custom FTP commands?
  348. You can tell curl to perform optional commands both before and/or after a
  349. file transfer. Study the -Q/--quote option.
  350. Since curl is used for file transfers, you don't use curl to just perform
  351. FTP commands without transferring anything. Therefore you must always specify
  352. a URL to transfer to/from even when doing custom FTP commands.
  353. 3.5 How can I disable the Pragma: nocache header?
  354. You can change all internally generated headers by adding a replacement with
  355. the -H/--header option. By adding a header with empty contents you safely
  356. disable that one. Use -H "Pragma:" to disable that specific header.
  357. 3.6 Does curl support ASP, XML, XHTML or HTML version Y?
  358. To curl, all contents are alike. It doesn't matter how the page was
  359. generated. It may be ASP, PHP, Perl, shell-script, SSI or plain
  360. HTML-files. There's no difference to curl and it doesn't even know what kind
  361. of language that generated the page.
  362. See also item 3.14 regarding javascript.
  363. 3.7 Can I use curl to delete/rename a file through FTP?
  364. Yes. You specify custom FTP commands with -Q/--quote.
  365. One example would be to delete a file after you have downloaded it:
  366. curl -O ftp://download.com/coolfile -Q '-DELE coolfile'
  367. or rename a file after upload:
  368. curl -T infile ftp://upload.com/dir/ -Q "-RNFR infile" -Q "-RNTO newname"
  369. 3.8 How do I tell curl to follow HTTP redirects?
  370. Curl does not follow so-called redirects by default. The Location: header
  371. that informs the client about this is only interpreted if you're using the
  372. -L/--location option. As in:
  373. curl -L http://redirector.com
  374. Not all redirects are HTTP ones, see 4.14
  375. 3.9 How do I use curl in my favorite programming language?
  376. There exist many language interfaces/bindings for curl that integrates it
  377. better with various languages. If you are fluid in a script language, you
  378. may very well opt to use such an interface instead of using the command line
  379. tool.
  380. Find out more about which languages that support curl directly, and how to
  381. install and use them, in the libcurl section of the curl web site:
  382. http://curl.haxx.se/libcurl/
  383. In October 2009, there were interfaces available for the following
  384. languages: Ada95, Basic, C, C++, Ch, Cocoa, D, Dylan, Eiffel, Euphoria,
  385. Ferite, Gambas, glib/GTK+, Haskell, ILE/RPG, Java, Lisp, Lua, Mono, .NET,
  386. Object-Pascal, O'Caml, Pascal, Perl, PHP, PostgreSQL, Python, R, Rexx, Ruby,
  387. Scheme, S-Lang, Smalltalk, SP-Forth, SPL, Tcl, Visual Basic, Visual FoxPro,
  388. Q, wxwidgets and XBLite. By the time you read this, additional ones may have
  389. appeared!
  390. 3.10 What about SOAP, WebDAV, XML-RPC or similar protocols over HTTP?
  391. Curl adheres to the HTTP spec, which basically means you can play with *any*
  392. protocol that is built on top of HTTP. Protocols such as SOAP, WEBDAV and
  393. XML-RPC are all such ones. You can use -X to set custom requests and -H to
  394. set custom headers (or replace internally generated ones).
  395. Using libcurl is of course just as fine and you'd just use the proper
  396. library options to do the same.
  397. 3.11 How do I POST with a different Content-Type?
  398. You can always replace the internally generated headers with -H/--header.
  399. To make a simple HTTP POST with text/xml as content-type, do something like:
  400. curl -d "datatopost" -H "Content-Type: text/xml" [URL]
  401. 3.12 Why do FTP specific features over HTTP proxy fail?
  402. Because when you use a HTTP proxy, the protocol spoken on the network will
  403. be HTTP, even if you specify a FTP URL. This effectively means that you
  404. normally can't use FTP specific features such as FTP upload and FTP quote
  405. etc.
  406. There is one exception to this rule, and that is if you can "tunnel through"
  407. the given HTTP proxy. Proxy tunneling is enabled with a special option (-p)
  408. and is generally not available as proxy admins usually disable tunneling to
  409. other ports than 443 (which is used for HTTPS access through proxies).
  410. 3.13 Why does my single/double quotes fail?
  411. To specify a command line option that includes spaces, you might need to
  412. put the entire option within quotes. Like in:
  413. curl -d " with spaces " url.com
  414. or perhaps
  415. curl -d ' with spaces ' url.com
  416. Exactly what kind of quotes and how to do this is entirely up to the shell
  417. or command line interpreter that you are using. For most unix shells, you
  418. can more or less pick either single (') or double (") quotes. For
  419. Windows/DOS prompts I believe you're forced to use double (") quotes.
  420. Please study the documentation for your particular environment. Examples in
  421. the curl docs will use a mix of both these ones as shown above. You must
  422. adjust them to work in your environment.
  423. Remember that curl works and runs on more operating systems than most single
  424. individuals have ever tried.
  425. 3.14 Does curl support Javascript or PAC (automated proxy config)?
  426. Many web pages do magic stuff using embedded Javascript. Curl and libcurl
  427. have no built-in support for that, so it will be treated just like any other
  428. contents.
  429. .pac files are a netscape invention and are sometimes used by organizations
  430. to allow them to differentiate which proxies to use. The .pac contents is
  431. just a Javascript program that gets invoked by the browser and that returns
  432. the name of the proxy to connect to. Since curl doesn't support Javascript,
  433. it can't support .pac proxy configuration either.
  434. Some workarounds usually suggested to overcome this Javascript dependency:
  435. - Depending on the Javascript complexity, write up a script that
  436. translates it to another language and execute that.
  437. - Read the Javascript code and rewrite the same logic in another language.
  438. - Implement a Javascript interpreter, people have successfully used the
  439. Mozilla Javascript engine in the past.
  440. - Ask your admins to stop this, for a static proxy setup or similar.
  441. 3.15 Can I do recursive fetches with curl?
  442. No. curl itself has no code that performs recursive operations, such as
  443. those performed by wget and similar tools.
  444. There exist wrapper scripts with that functionality (for example the
  445. curlmirror perl script), and you can write programs based on libcurl to do
  446. it, but the command line tool curl itself cannot.
  447. 3.16 What certificates do I need when I use SSL?
  448. There are three different kinds of "certificates" to keep track of when we
  449. talk about using SSL-based protocols (HTTPS or FTPS) using curl or libcurl.
  450. - Client certificate. The server you communicate may require that you can
  451. provide this in order to prove that you actually are who you claim to be.
  452. If the server doesn't require this, you don't need a client certificate.
  453. - Server certificate. The server you communicate with has a server
  454. certificate. You can and should verify this certificate to make sure that
  455. you are truly talking to the real server and not a server impersonating
  456. it.
  457. - Certificate Authority certificate ("CA cert"). You often have several CA
  458. certs in a CA cert bundle that can be used to verify a server certificate
  459. that was signed by one of the authorities in the bundle. curl comes with a
  460. default CA cert bundle. You can override the default.
  461. The server certificate verification process is made by using a Certificate
  462. Authority certificate ("CA cert") that was used to sign the server
  463. certificate. Server certificate verification is enabled by default in curl
  464. and libcurl and is often the reason for problems as explained in FAQ entry
  465. 4.12 and the SSLCERTS document
  466. (http://curl.haxx.se/docs/sslcerts.html). Server certificates that are
  467. "self-signed" or otherwise signed by a CA that you do not have a CA cert
  468. for, cannot be verified. If the verification during a connect fails, you
  469. are refused access. You then need to explicitly disable the verification
  470. to connect to the server.
  471. 3.17 How do I list the root dir of an FTP server?
  472. There are two ways. The way defined in the RFC is to use an encoded slash
  473. in the first path part. List the "/tmp" dir like this:
  474. curl ftp://ftp.sunet.se/%2ftmp/
  475. or the not-quite-kosher-but-more-readable way, by simply starting the path
  476. section of the URL with a slash:
  477. curl ftp://ftp.sunet.se//tmp/
  478. 3.18 Can I use curl to send a POST/PUT and not wait for a response?
  479. No.
  480. But you could easily write your own program using libcurl to do such stunts.
  481. 4. Running Problems
  482. 4.1 Problems connecting to SSL servers.
  483. It took a very long time before we could sort out why curl had problems to
  484. connect to certain SSL servers when using SSLeay or OpenSSL v0.9+. The
  485. error sometimes showed up similar to:
  486. 16570:error:1407D071:SSL routines:SSL2_READ:bad mac decode:s2_pkt.c:233:
  487. It turned out to be because many older SSL servers don't deal with SSLv3
  488. requests properly. To correct this problem, tell curl to select SSLv2 from
  489. the command line (-2/--sslv2).
  490. There have also been examples where the remote server didn't like the SSLv2
  491. request and instead you had to force curl to use SSLv3 with -3/--sslv3.
  492. 4.2 Why do I get problems when I use & or % in the URL?
  493. In general unix shells, the & symbol is treated specially and when used, it
  494. runs the specified command in the background. To safely send the & as a part
  495. of a URL, you should quote the entire URL by using single (') or double (")
  496. quotes around it. Similar problems can also occur on some shells with other
  497. characters, including ?*!$~(){}<>\|;`. When in doubt, quote the URL.
  498. An example that would invoke a remote CGI that uses &-symbols could be:
  499. curl 'http://www.altavista.com/cgi-bin/query?text=yes&q=curl'
  500. In Windows, the standard DOS shell treats the %-symbol specially and you
  501. need to use TWO %-symbols for each single one you want to use in the URL.
  502. Also note that if you want the literal %-symbol to be part of the data you
  503. pass in a POST using -d/--data you must encode it as '%25' (which then also
  504. needs the %-symbol doubled on Windows machines).
  505. 4.3 How can I use {, }, [ or ] to specify multiple URLs?
  506. Because those letters have a special meaning to the shell, and to be used in
  507. a URL specified to curl you must quote them.
  508. An example that downloads two URLs (sequentially) would do:
  509. curl '{curl,www}.haxx.se'
  510. To be able to use those letters as actual parts of the URL (without using
  511. them for the curl URL "globbing" system), use the -g/--globoff option:
  512. curl -g 'www.site.com/weirdname[].html'
  513. 4.4 Why do I get downloaded data even though the web page doesn't exist?
  514. Curl asks remote servers for the page you specify. If the page doesn't exist
  515. at the server, the HTTP protocol defines how the server should respond and
  516. that means that headers and a "page" will be returned. That's simply how
  517. HTTP works.
  518. By using the --fail option you can tell curl explicitly to not get any data
  519. if the HTTP return code doesn't say success.
  520. 4.5 Why do I get return code XXX from a HTTP server?
  521. RFC2616 clearly explains the return codes. This is a short transcript. Go
  522. read the RFC for exact details:
  523. 4.5.1 "400 Bad Request"
  524. The request could not be understood by the server due to malformed
  525. syntax. The client SHOULD NOT repeat the request without modifications.
  526. 4.5.2 "401 Unauthorized"
  527. The request requires user authentication.
  528. 4.5.3 "403 Forbidden"
  529. The server understood the request, but is refusing to fulfill it.
  530. Authorization will not help and the request SHOULD NOT be repeated.
  531. 4.5.4 "404 Not Found"
  532. The server has not found anything matching the Request-URI. No indication
  533. is given of whether the condition is temporary or permanent.
  534. 4.5.5 "405 Method Not Allowed"
  535. The method specified in the Request-Line is not allowed for the resource
  536. identified by the Request-URI. The response MUST include an Allow header
  537. containing a list of valid methods for the requested resource.
  538. 4.5.6 "301 Moved Permanently"
  539. If you get this return code and an HTML output similar to this:
  540. <H1>Moved Permanently</H1> The document has moved <A
  541. HREF="http://same_url_now_with_a_trailing_slash/">here</A>.
  542. it might be because you request a directory URL but without the trailing
  543. slash. Try the same operation again _with_ the trailing URL, or use the
  544. -L/--location option to follow the redirection.
  545. 4.6 Can you tell me what error code 142 means?
  546. All curl error codes are described at the end of the man page, in the
  547. section called "EXIT CODES".
  548. Error codes that are larger than the highest documented error code means
  549. that curl has exited due to a crash. This is a serious error, and we
  550. appreciate a detailed bug report from you that describes how we could go
  551. ahead and repeat this!
  552. 4.7 How do I keep user names and passwords secret in Curl command lines?
  553. This problem has two sides:
  554. The first part is to avoid having clear-text passwords in the command line
  555. so that they don't appear in 'ps' outputs and similar. That is easily
  556. avoided by using the "-K" option to tell curl to read parameters from a file
  557. or stdin to which you can pass the secret info. curl itself will also
  558. attempt to "hide" the given password by blanking out the option - this
  559. doesn't work on all platforms.
  560. To keep the passwords in your account secret from the rest of the world is
  561. not a task that curl addresses. You could of course encrypt them somehow to
  562. at least hide them from being read by human eyes, but that is not what
  563. anyone would call security.
  564. Also note that regular HTTP (using Basic authentication) and FTP passwords
  565. are sent in clear across the network. All it takes for anyone to fetch them
  566. is to listen on the network. Eavesdropping is very easy. Use more secure
  567. authentication methods (like Digest, Negotiate or even NTLM) or consider the
  568. SSL-based alternatives HTTPS and FTPS.
  569. 4.8 I found a bug!
  570. It is not a bug if the behavior is documented. Read the docs first.
  571. Especially check out the KNOWN_BUGS file, it may be a documented bug!
  572. If it is a problem with a binary you've downloaded or a package for your
  573. particular platform, try contacting the person who built the package/archive
  574. you have.
  575. If there is a bug, read the BUGS document first. Then report it as described
  576. in there.
  577. 4.9 Curl can't authenticate to the server that requires NTLM?
  578. This is supported in curl 7.10.6 or later. No earlier curl version knows
  579. of this magic. Later versions require the OpenSSL, GnuTLS or Microsoft
  580. Windows libraries to provide this functionality. Using the NSS library
  581. will not provide NTLM authentication functionality in curl.
  582. NTLM is a Microsoft proprietary protocol. Proprietary formats are evil. You
  583. should not use such ones.
  584. 4.10 My HTTP request using HEAD, PUT or DELETE doesn't work!
  585. Many web servers allow or demand that the administrator configures the
  586. server properly for these requests to work on the web server.
  587. Some servers seem to support HEAD only on certain kinds of URLs.
  588. To fully grasp this, try the documentation for the particular server
  589. software you're trying to interact with. This is not anything curl can do
  590. anything about.
  591. 4.11 Why does my HTTP range requests return the full document?
  592. Because the range may not be supported by the server, or the server may
  593. choose to ignore it and return the full document anyway.
  594. 4.12 Why do I get "certificate verify failed" ?
  595. You invoke curl 7.10 or later to communicate on a https:// URL and get an
  596. error back looking something similar to this:
  597. curl: (35) SSL: error:14090086:SSL routines:
  598. SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
  599. Then it means that curl couldn't verify that the server's certificate was
  600. good. Curl verifies the certificate using the CA cert bundle that comes with
  601. the curl installation.
  602. To disable the verification (which makes it act like curl did before 7.10),
  603. use -k. This does however enable man-in-the-middle attacks.
  604. If you get this failure but are having a CA cert bundle installed and used,
  605. the server's certificate is not signed by one of the CA's in the bundle. It
  606. might for example be self-signed. You then correct this problem by obtaining
  607. a valid CA cert for the server. Or again, decrease the security by disabling
  608. this check.
  609. Details are also in the SSLCERTS file in the release archives, found online
  610. here: http://curl.haxx.se/docs/sslcerts.html
  611. 4.13 Why is curl -R on Windows one hour off?
  612. During daylight savings time, when -R is used, curl will set a time that
  613. appears one hour off. This happens due to a flaw in how Windows stores and
  614. uses file modification times and it is not easily worked around. For details
  615. on this problem, read this: http://www.codeproject.com/datetime/dstbugs.asp
  616. 4.14 Redirects work in browser but not with curl!
  617. curl supports HTTP redirects fine (see item 3.8). Browsers generally support
  618. at least two other ways to perform directs that curl does not:
  619. - Meta tags. You can write a HTML tag that will cause the browser to
  620. redirect to another given URL after a certain time.
  621. - Javascript. You can write a Javascript program embedded in a HTML page
  622. that redirects the browser to another given URL.
  623. There is no way to make curl follow these redirects. You must either
  624. manually figure out what the page is set to do, or you write a script that
  625. parses the results and fetches the new URL.
  626. 4.15 FTPS doesn't work
  627. curl supports FTPS (sometimes known as FTP-SSL) both implicit and explicit
  628. mode.
  629. When a URL is used that starts with FTPS://, curl assumes implicit SSL on
  630. the control connection and will therefore immediately connect and try to
  631. speak SSL. FTPS:// connections default to port 990.
  632. To use explicit FTPS, you use a FTP:// URL and the --ftp-ssl option (or one
  633. of its related flavours). This is the most common method, and the one
  634. mandated by RFC4217. This kind of connection then of course uses the
  635. standard FTP port 21 by default.
  636. 4.16 My HTTP POST or PUT requests are slow!
  637. libcurl makes all POST and PUT requests (except for POST requests with a
  638. very tiny request body) use the "Expect: 100-continue" header. This header
  639. allows the server to deny the operation early so that libcurl can bail out
  640. already before having to send any data. This is useful in authentication
  641. cases and others.
  642. However, many servers don't implement the Expect: stuff properly and if the
  643. server doesn't respond (positively) within 1 second libcurl will continue
  644. and send off the data anyway.
  645. You can disable libcurl's use of the Expect: header the same way you disable
  646. any header, using -H / CURLOPT_HTTPHEADER, or by forcing it to use HTTP 1.0.
  647. 4.17 Non-functional connect timeouts
  648. In most Windows setups having a timeout longer than 21 seconds make no
  649. difference, as it will only send 3 TCP SYN packets and no more. The second
  650. packet sent three seconds after the first and the third six seconds after
  651. the second. No more than three packets are sent, no matter how long the
  652. timeout is set.
  653. See option TcpMaxConnectRetransmissions on this page:
  654. http://support.microsoft.com/?scid=kb%3Ben-us%3B175523&x=6&y=7
  655. Also, even on non-Windows systems there may run a firewall or anti-virus
  656. software or similar that accepts the connection but does not actually do
  657. anything else. This will make (lib)curl to consider the connection connected
  658. and thus the connect timeout won't trigger.
  659. 4.18 file:// URLs containing drive letters (Windows, NetWare)
  660. When using cURL to try to download a local file, one might use a URL
  661. in this format:
  662. file://D:/blah.txt
  663. You'll find that even if D:\blah.txt does exist, cURL returns a 'file
  664. not found' error.
  665. According to RFC 1738 (http://www.faqs.org/rfcs/rfc1738.html),
  666. file:// URLs must contain a host component, but it is ignored by
  667. most implementations. In the above example, 'D:' is treated as the
  668. host component, and is taken away. Thus, cURL tries to open '/blah.txt'.
  669. If your system is installed to drive C:, that will resolve to 'C:\blah.txt',
  670. and if that doesn't exist you will get the not found error.
  671. To fix this problem, use file:// URLs with *three* leading slashes:
  672. file:///D:/blah.txt
  673. Alternatively, if it makes more sense, specify 'localhost' as the host
  674. component:
  675. file://localhost/D:/blah.txt
  676. In either case, cURL should now be looking for the correct file.
  677. 5. libcurl Issues
  678. 5.1 Is libcurl thread-safe?
  679. Yes.
  680. We have written the libcurl code specifically adjusted for multi-threaded
  681. programs. libcurl will use thread-safe functions instead of non-safe ones if
  682. your system has such.
  683. If you use a OpenSSL-powered libcurl in a multi-threaded environment, you
  684. need to provide one or two locking functions:
  685. http://www.openssl.org/docs/crypto/threads.html
  686. If you use a GnuTLS-powered libcurl in a multi-threaded environment, you
  687. need to provide locking function(s) for libgcrypt (which is used by GnuTLS
  688. for the crypto functions).
  689. http://www.gnu.org/software/gnutls/manual/html_node/Multi_002dthreaded-applications.html
  690. No special locking is needed with a NSS-powered libcurl. NSS is thread-safe.
  691. 5.2 How can I receive all data into a large memory chunk?
  692. [ See also the examples/getinmemory.c source ]
  693. You are in full control of the callback function that gets called every time
  694. there is data received from the remote server. You can make that callback do
  695. whatever you want. You do not have to write the received data to a file.
  696. One solution to this problem could be to have a pointer to a struct that you
  697. pass to the callback function. You set the pointer using the
  698. CURLOPT_WRITEDATA option. Then that pointer will be passed to the callback
  699. instead of a FILE * to a file:
  700. /* imaginary struct */
  701. struct MemoryStruct {
  702. char *memory;
  703. size_t size;
  704. };
  705. /* imaginary callback function */
  706. size_t
  707. WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)
  708. {
  709. size_t realsize = size * nmemb;
  710. struct MemoryStruct *mem = (struct MemoryStruct *)data;
  711. mem->memory = (char *)realloc(mem->memory, mem->size + realsize + 1);
  712. if (mem->memory) {
  713. memcpy(&(mem->memory[mem->size]), ptr, realsize);
  714. mem->size += realsize;
  715. mem->memory[mem->size] = 0;
  716. }
  717. return realsize;
  718. }
  719. 5.3 How do I fetch multiple files with libcurl?
  720. libcurl has excellent support for transferring multiple files. You should
  721. just repeatedly set new URLs with curl_easy_setopt() and then transfer it
  722. with curl_easy_perform(). The handle you get from curl_easy_init() is not
  723. only reusable, but you're even encouraged to reuse it if you can, as that
  724. will enable libcurl to use persistent connections.
  725. 5.4 Does libcurl do Winsock initialization on win32 systems?
  726. Yes, if told to in the curl_global_init() call.
  727. 5.5 Does CURLOPT_WRITEDATA and CURLOPT_READDATA work on win32 ?
  728. Yes, but you cannot open a FILE * and pass the pointer to a DLL and have
  729. that DLL use the FILE * (as the DLL and the client application cannot access
  730. each others' variable memory areas). If you set CURLOPT_WRITEDATA you must
  731. also use CURLOPT_WRITEFUNCTION as well to set a function that writes the
  732. file, even if that simply writes the data to the specified FILE *.
  733. Similarly, if you use CURLOPT_READDATA you must also specify
  734. CURLOPT_READFUNCTION.
  735. 5.6 What about Keep-Alive or persistent connections?
  736. curl and libcurl have excellent support for persistent connections when
  737. transferring several files from the same server. Curl will attempt to reuse
  738. connections for all URLs specified on the same command line/config file, and
  739. libcurl will reuse connections for all transfers that are made using the
  740. same libcurl handle.
  741. 5.7 Link errors when building libcurl on Windows!
  742. You need to make sure that your project, and all the libraries (both static
  743. and dynamic) that it links against, are compiled/linked against the same run
  744. time library.
  745. This is determined by the /MD, /ML, /MT (and their corresponding /M?d)
  746. options to the command line compiler. /MD (linking against MSVCRT dll) seems
  747. to be the most commonly used option.
  748. When building an application that uses the static libcurl library, you must
  749. add -DCURL_STATICLIB to your CFLAGS. Otherwise the linker will look for
  750. dynamic import symbols. If you get linker error like "unknown symbol
  751. __imp__curl_easy_init ..." you have linked against the wrong (static)
  752. library. If you want to use the libcurl.dll and import lib, you don't need
  753. any extra CFLAGS, but use one of the import libraries below. These are the
  754. libraries produced by the various lib/Makefile.* files:
  755. Target: static lib. import lib for libcurl*.dll.
  756. -----------------------------------------------------------
  757. MingW: libcurl.a libcurldll.a
  758. MSVC (release): libcurl.lib libcurl_imp.lib
  759. MSVC (debug): libcurld.lib libcurld_imp.lib
  760. Borland: libcurl.lib libcurl_imp.lib
  761. 5.8 libcurl.so.3: open failed: No such file or directory
  762. This is an error message you might get when you try to run a program linked
  763. with a shared version of libcurl and your run-time linker (ld.so) couldn't
  764. find the shared library named libcurl.so.3.
  765. You need to make sure that ld.so finds libcurl.so.3. You can do that
  766. multiple ways, and it differs somewhat between different operating systems,
  767. but they are usually:
  768. * Add an option to the linker command line that specify the hard-coded path
  769. the run-time linker should check for the lib (usually -R)
  770. * Set an environment variable (LD_LIBRARY_PATH for example) where ld.so
  771. should check for libs
  772. * Adjust the system's config to check for libs in the directory where you've
  773. put the dir (like Linux's /etc/ld.so.conf)
  774. 'man ld.so' and 'man ld' will tell you more details
  775. 5.9 How does libcurl resolve host names?
  776. libcurl supports a large a number of different name resolve functions. One
  777. of them is picked at build-time and will be used unconditionally. Thus, if
  778. you want to change name resolver function you must rebuild libcurl and tell
  779. it to use a different function.
  780. - The non-ipv6 resolver that can use one out of four host name resolve calls
  781. (depending on what your system supports):
  782. A - gethostbyname()
  783. B - gethostbyname_r() with 3 arguments
  784. C - gethostbyname_r() with 5 arguments
  785. D - gethostbyname_r() with 6 arguments
  786. - The ipv6-resolver that uses getaddrinfo()
  787. - The c-ares based name resolver that uses the c-ares library for resolves.
  788. Using this offers asynchronous name resolves but it currently has no IPv6
  789. support.
  790. - The Windows threaded resolver. It use:
  791. A - gethostbyname() on plain ipv4 windows hosts
  792. B - getaddrinfo() on ipv6-enabled windows hosts
  793. Also note that libcurl never resolves or reverse-lookups addresses given as
  794. pure numbers, such as 127.0.0.1 or ::1.
  795. 5.10 How do I prevent libcurl from writing the response to stdout?
  796. libcurl provides a default built-in write function that writes received data
  797. to stdout. Set the CURLOPT_WRITEFUNCTION to receive the data, or possibly
  798. set CURLOPT_WRITEDATA to a different FILE * handle.
  799. 5.11 How do I make libcurl not receive the whole HTTP response?
  800. You make the write callback (or progress callback) return an error and
  801. libcurl will then abort the transfer.
  802. 5.12 Can I make libcurl fake or hide my real IP address?
  803. No. libcurl operates on a higher level than so. Besides, faking IP address
  804. would imply sending IP packages with a made-up source address, and then you
  805. normally get a problem with intercepting the packages sent back as they
  806. would then not be routed to you!
  807. If you use a proxy to access remote sites, the sites will not see your local
  808. IP address but instead the address of the proxy.
  809. Also note that on many networks NATs or other IP-munging techniques are used
  810. that makes you see and use a different IP address locally than what the
  811. remote server will see you coming from.
  812. 5.13 How do I stop an ongoing transfer?
  813. There are several ways, but none of them are instant. There is no function
  814. you can call from another thread or similar that will stop it immediately.
  815. Instead you need to make sure that one of the callbacks you use return an
  816. appropriate value that will stop the transfer.
  817. Suitable callbacks that you can do this with include the progress callback,
  818. the read callback and the write callback.
  819. If you're using the multi interface, you also stop a transfer by removing
  820. the particular easy handle from the multi stack.
  821. 5.14 Using C++ non-static functions for callbacks?
  822. libcurl is a C library, it doesn't know anything about C++ member functions.
  823. You can overcome this "limitation" with a relative ease using a static
  824. member function that is passed a pointer to the class:
  825. // f is the pointer to your object.
  826. static YourClass::staticFunction(void *buffer, size_t sz, size_t n, void *f)
  827. {
  828. // Call non-static member function.
  829. static_cast<YourClass*>(f)->nonStaticFunction();
  830. }
  831. // This is how you pass pointer to the static function:
  832. curl_easy_setopt(hcurl, CURLOPT_WRITEFUNCTION, YourClass:staticFunction);
  833. curl_easy_setopt(hcurl, CURLOPT_WRITEDATA, this);
  834. 5.15 How do I get an FTP directory listing?
  835. If you end the FTP URL you request with a slash, libcurl will provide you
  836. with a directory listing of that given directory. You can also set
  837. CURLOPT_CUSTOMREQUEST to alter what exact listing command libcurl would use
  838. to list the files.
  839. The follow-up question that tend to follow the previous one, is how a
  840. program is supposed to parse the directory listing. How does it know what's
  841. a file and what's a dir and what's a symlink etc. The harsh reality is that
  842. FTP provides no such fine and easy-to-parse output. The output format FTP
  843. servers respond to LIST commands are entirely at the server's own liking and
  844. the NLST output doesn't reveal any types and in many cases don't even
  845. include all the directory entries. Also, both LIST and NLST tend to hide
  846. unix-style hidden files (those that start with a dot) by default so you need
  847. to do "LIST -a" or similar to see them.
  848. The application thus needs to parse the LIST output. One such existing
  849. list parser is available at http://cr.yp.to/ftpparse.html
  850. 6. License Issues
  851. Curl and libcurl are released under a MIT/X derivate license. The license is
  852. very liberal and should not impose a problem for your project. This section
  853. is just a brief summary for the cases we get the most questions. (Parts of
  854. this section was much enhanced by Bjorn Reese.)
  855. We are not lawyers and this is not legal advice. You should probably consult
  856. one if you want true and accurate legal insights without our prejudice.
  857. 6.1 I have a GPL program, can I use the libcurl library?
  858. Yes!
  859. Since libcurl may be distributed under the MIT/X derivate license, it can be
  860. used together with GPL in any software.
  861. 6.2 I have a closed-source program, can I use the libcurl library?
  862. Yes!
  863. libcurl does not put any restrictions on the program that uses the library.
  864. 6.3 I have a BSD licensed program, can I use the libcurl library?
  865. Yes!
  866. libcurl does not put any restrictions on the program that uses the library.
  867. 6.4 I have a program that uses LGPL libraries, can I use libcurl?
  868. Yes!
  869. The LGPL license doesn't clash with other licenses.
  870. 6.5 Can I modify curl/libcurl for my program and keep the changes secret?
  871. Yes!
  872. The MIT/X derivate license practically allows you to do almost anything with
  873. the sources, on the condition that the copyright texts in the sources are
  874. left intact.
  875. 6.6 Can you please change the curl/libcurl license to XXXX?
  876. No.
  877. We have carefully picked this license after years of development and
  878. discussions and a large amount of people have contributed with source code
  879. knowing that this is the license we use. This license puts the restrictions
  880. we want on curl/libcurl and it does not spread to other programs or
  881. libraries that use it. It should be possible for everyone to use libcurl or
  882. curl in their projects, no matter what license they already have in use.
  883. 6.7 What are my obligations when using libcurl in my commercial apps?
  884. Next to none. All you need to adhere to is the MIT-style license (stated in
  885. the COPYING file) which basically says you have to include the copyright
  886. notice in "all copies" and that you may not use the copyright holder's name
  887. when promoting your software.
  888. You do not have to release any of your source code.
  889. You do not have to reveal or make public any changes to the libcurl source
  890. code.
  891. You do not have to reveal or make public that you are using libcurl within
  892. your app.
  893. As can be seen here: http://curl.haxx.se/docs/companies.html and
  894. elsewhere, more and more companies are discovering the power
  895. of libcurl and take advantage of it even in commercial environments.
  896. 7. PHP/CURL Issues
  897. 7.1 What is PHP/CURL?
  898. The module for PHP that makes it possible for PHP programs to access curl-
  899. functions from within PHP.
  900. In the cURL project we call this module PHP/CURL to differentiate it from
  901. curl the command line tool and libcurl the library. The PHP team however
  902. does not refer to it like this (for unknown reasons). They call it plain
  903. CURL (often using all caps) or sometimes ext/curl, but both cause much
  904. confusion to users which in turn gives us a higher question load.
  905. 7.2 Who write PHP/CURL?
  906. PHP/CURL is a module that comes with the regular PHP package. It depends and
  907. uses libcurl, so you need to have libcurl installed properly first before
  908. PHP/CURL can be used. PHP/CURL was initially written by Sterling Hughes.
  909. 7.3 Can I perform multiple requests using the same handle?
  910. Yes - at least in PHP version 4.3.8 and later (this has been known to not
  911. work in earlier versions, but the exact version when it started to work is
  912. unknown to me).
  913. After a transfer, you just set new options in the handle and make another
  914. transfer. This will make libcurl to re-use the same connection if it can.