must first ask the server what it supports:
~~~c
- curl_easy_setopt(handle, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST|CURLAUTH_BASIC);
+ curl_easy_setopt(handle, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST | CURLAUTH_BASIC);
~~~
For convenience, you can use the *CURLAUTH_ANY* define (instead of a list with
libcurl to post it all to the remote site:
~~~c
- char *data="name=daniel&project=curl";
+ char *data = "name=daniel&project=curl";
curl_easy_setopt(handle, CURLOPT_POSTFIELDS, data);
curl_easy_setopt(handle, CURLOPT_URL, "http://posthere.com/");
that list to libcurl.
~~~c
- struct curl_slist *headers=NULL;
+ struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: text/xml");
/* post binary data */
The MIME API example above is expressed as follows using this function:
~~~c
- struct curl_httppost *post=NULL;
- struct curl_httppost *last=NULL;
+ struct curl_httppost *post = NULL;
+ struct curl_httppost *last = NULL;
curl_formadd(&post, &last,
CURLFORM_COPYNAME, "name",
CURLFORM_COPYCONTENTS, "daniel", CURLFORM_END);
handle:
~~~c
- struct curl_slist *headers=NULL;
+ struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: text/xml");
curl_formadd(&post, &last,
~~~c
part = curl_mime_addpart(multipart);
curl_mime_name(part, "logotype-image");
- curl_mime_data_cb(part, (curl_off_t) -1, fread, fseek, NULL, stdin);
+ curl_mime_data_cb(part, (curl_off_t)-1, fread, fseek, NULL, stdin);
~~~
curl_mime_name(3) always copies the field name. The special filename "-" is
~~~c
part = curl_mime_addpart(multipart);
curl_mime_name(part, "stream");
- curl_mime_data_cb(part, (curl_off_t) datasize,
+ curl_mime_data_cb(part, (curl_off_t)datasize,
myreadfunc, NULL, NULL, arg);
curl_mime_filename(part, "archive.zip");
curl_mime_type(part, "application/zip");
~~~c
part = curl_mime_addpart(multipart);
curl_mime_name(part, "memfile");
- curl_mime_data(part, databuffer, (curl_off_t) sizeof databuffer);
+ curl_mime_data(part, databuffer, (curl_off_t)sizeof(databuffer));
curl_mime_filename(part, "memfile.bin");
~~~
~~~c
class AClass {
- static size_t write_data(void *ptr, size_t size, size_t nmemb,
- void *ourpointer)
- {
- /* do what you want with the data */
- }
- }
+ static size_t write_data(void *ptr, size_t size, size_t nmemb,
+ void *ourpointer)
+ {
+ /* do what you want with the data */
+ }
+}
~~~
# Proxies
think fit. Adding headers is this easy:
~~~c
-struct curl_slist *headers=NULL; /* init to NULL is important */
+struct curl_slist *headers = NULL; /* init to NULL is important */
headers = curl_slist_append(headers, "Hey-server-hey: how are you?");
headers = curl_slist_append(headers, "X-silly-content: yes");