<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="fr">
	<id>https://wicri-demo.istex.fr/Wicri/Outils/fr/index.php?action=history&amp;feed=atom&amp;title=Libcurl</id>
	<title>Libcurl - Historique des versions</title>
	<link rel="self" type="application/atom+xml" href="https://wicri-demo.istex.fr/Wicri/Outils/fr/index.php?action=history&amp;feed=atom&amp;title=Libcurl"/>
	<link rel="alternate" type="text/html" href="https://wicri-demo.istex.fr/Wicri/Outils/fr/index.php?title=Libcurl&amp;action=history"/>
	<updated>2026-04-18T23:48:28Z</updated>
	<subtitle>Historique des versions pour cette page sur le wiki</subtitle>
	<generator>MediaWiki 1.31.10</generator>
	<entry>
		<id>https://wicri-demo.istex.fr/Wicri/Outils/fr/index.php?title=Libcurl&amp;diff=3955&amp;oldid=prev</id>
		<title>imported&gt;Jacques Ducloy : 1 révision importée</title>
		<link rel="alternate" type="text/html" href="https://wicri-demo.istex.fr/Wicri/Outils/fr/index.php?title=Libcurl&amp;diff=3955&amp;oldid=prev"/>
		<updated>2017-06-16T17:55:00Z</updated>

		<summary type="html">&lt;p&gt;1 révision importée&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;fr&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Version précédente&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Version du 16 juin 2017 à 17:55&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;fr&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(Aucune différence)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>imported&gt;Jacques Ducloy</name></author>
		
	</entry>
	<entry>
		<id>https://wicri-demo.istex.fr/Wicri/Outils/fr/index.php?title=Libcurl&amp;diff=3954&amp;oldid=prev</id>
		<title>imported&gt;Jacques Ducloy : /* Autre version */</title>
		<link rel="alternate" type="text/html" href="https://wicri-demo.istex.fr/Wicri/Outils/fr/index.php?title=Libcurl&amp;diff=3954&amp;oldid=prev"/>
		<updated>2012-09-19T12:56:18Z</updated>

		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Autre version&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Nouvelle page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{minuscule}}&lt;br /&gt;
&lt;br /&gt;
'''&amp;lt;code&amp;gt;libcurl&amp;lt;/code&amp;gt;''' est une bibliothèque logicielle écrite en langage C qui permet de manipuler des ressources repérées par leurs URL.&lt;br /&gt;
&lt;br /&gt;
La commande '''&amp;lt;code&amp;gt;[[cURL]]&amp;lt;/code&amp;gt;''' est écrite à l'aide de cette bibliothèque.&lt;br /&gt;
&lt;br /&gt;
==Exemples d'emploi==&lt;br /&gt;
&lt;br /&gt;
===Exemple de base===&lt;br /&gt;
&lt;br /&gt;
Le programme ci dessous&amp;lt;ref&amp;gt;Exemple extrait du site http://stackoverflow.com et testé sur MacBook Pro sous Mac OS X&amp;lt;br/&amp;gt;http://stackoverflow.com/questions/2329571/c-libcurl-get-output-into-a-string&amp;lt;/ref&amp;gt; accède au document (html) localisé à l'url [http://ticri.inpl-nancy.fr http://ticri.inpl-nancy.fr], le range dans la chaîne contenue dans la structure s et l'imprime.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;curl/curl.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
struct string {&lt;br /&gt;
  char *ptr;&lt;br /&gt;
  size_t len;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
void init_string(struct string *s) {&lt;br /&gt;
  s-&amp;gt;len = 0;&lt;br /&gt;
  s-&amp;gt;ptr = malloc(s-&amp;gt;len+1);&lt;br /&gt;
  if (s-&amp;gt;ptr == NULL) {&lt;br /&gt;
    fprintf(stderr, &amp;quot;malloc() failed\n&amp;quot;);&lt;br /&gt;
    exit(EXIT_FAILURE);&lt;br /&gt;
  }&lt;br /&gt;
  s-&amp;gt;ptr[0] = '\0';&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
size_t writefunc(void *ptr, size_t size, size_t nmemb, struct string *s)&lt;br /&gt;
{&lt;br /&gt;
  size_t new_len = s-&amp;gt;len + size*nmemb;&lt;br /&gt;
  s-&amp;gt;ptr = realloc(s-&amp;gt;ptr, new_len+1);&lt;br /&gt;
  if (s-&amp;gt;ptr == NULL) {&lt;br /&gt;
    fprintf(stderr, &amp;quot;realloc() failed\n&amp;quot;);&lt;br /&gt;
    exit(EXIT_FAILURE);&lt;br /&gt;
  }&lt;br /&gt;
  memcpy(s-&amp;gt;ptr+s-&amp;gt;len, ptr, size*nmemb);&lt;br /&gt;
  s-&amp;gt;ptr[new_len] = '\0';&lt;br /&gt;
  s-&amp;gt;len = new_len;&lt;br /&gt;
&lt;br /&gt;
  return size*nmemb;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
  CURL *curl;&lt;br /&gt;
  CURLcode res;&lt;br /&gt;
&lt;br /&gt;
  curl = curl_easy_init();&lt;br /&gt;
  if(curl) {&lt;br /&gt;
    struct string s;&lt;br /&gt;
    init_string(&amp;amp;s);&lt;br /&gt;
&lt;br /&gt;
    curl_easy_setopt(curl, CURLOPT_URL, &amp;quot;http://ticri.inpl-nancy.fr&amp;quot;);&lt;br /&gt;
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);&lt;br /&gt;
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &amp;amp;s);&lt;br /&gt;
    res = curl_easy_perform(curl);&lt;br /&gt;
&lt;br /&gt;
    printf(&amp;quot;%s\n&amp;quot;, s.ptr);&lt;br /&gt;
    free(s.ptr);&lt;br /&gt;
&lt;br /&gt;
    /* always cleanup */&lt;br /&gt;
    curl_easy_cleanup(curl);&lt;br /&gt;
  }&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Si &amp;lt;code&amp;gt;testCurl.c&amp;lt;/code&amp;gt; est le nom du fichier correspondant au code source précédent, la compilation se fait généralement par une commande du type :&lt;br /&gt;
&amp;lt;source lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
gcc testCurl.c -lcurl -ll -o testCurl&lt;br /&gt;
./testCurl&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Autre version===&lt;br /&gt;
&lt;br /&gt;
Le [[Dilib, module Buffer|module Buffer]] de la [[bibliothèque Dilib]] permet une écriture plus simple :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;curl/curl.h&amp;gt;&lt;br /&gt;
#include &amp;quot;Buffer.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Buffer *buf1;&lt;br /&gt;
&lt;br /&gt;
size_t writefunc(void *ptr, size_t size, size_t nmemb, Buffer *buf)&lt;br /&gt;
{&lt;br /&gt;
  BufferStrncat(buf, ptr, size*nmemb);&lt;br /&gt;
&lt;br /&gt;
  return size*nmemb;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
  CURL *curl;&lt;br /&gt;
  CURLcode res;&lt;br /&gt;
&lt;br /&gt;
  curl = curl_easy_init();&lt;br /&gt;
  buf1=BufferCreate(10000,10000);&lt;br /&gt;
  BufferStrcpy(buf1,&amp;quot;&amp;quot;);&lt;br /&gt;
  if(curl) {&lt;br /&gt;
&lt;br /&gt;
    curl_easy_setopt(curl, CURLOPT_URL, &amp;quot;http://ticri.inpl-nancy.fr&amp;quot;);&lt;br /&gt;
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);&lt;br /&gt;
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, buf1);&lt;br /&gt;
    res = curl_easy_perform(curl);&lt;br /&gt;
&lt;br /&gt;
    printf(&amp;quot;%s\n&amp;quot;, BufferString(buf1));&lt;br /&gt;
&lt;br /&gt;
    /* always cleanup */&lt;br /&gt;
    curl_easy_cleanup(curl);&lt;br /&gt;
  }&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Voir aussi==&lt;br /&gt;
=== Liens externes ===&lt;br /&gt;
* [http://curl.haxx.se/ Site officiel]&lt;br /&gt;
===Notes===&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Catégorie:Logiciel sous licence libre]]&lt;br /&gt;
[[Catégorie:HTTP]]&lt;br /&gt;
[[Catégorie:libcurl]]&lt;/div&gt;</summary>
		<author><name>imported&gt;Jacques Ducloy</name></author>
		
	</entry>
</feed>