xref: /curl/docs/libcurl/curl_formget.md (revision b935fd4a)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: curl_formget
5Section: 3
6Source: libcurl
7See-also:
8  - curl_formadd (3)
9  - curl_mime_init (3)
10Protocol:
11  - HTTP
12---
13
14# NAME
15
16curl_formget - serialize a previously built multipart form POST chain
17
18# SYNOPSIS
19
20~~~c
21#include <curl/curl.h>
22
23int curl_formget(struct curl_httppost * form, void *userp,
24                 curl_formget_callback append);
25~~~
26
27# DESCRIPTION
28
29curl_formget() serializes data previously built with curl_formadd(3). It
30accepts a void pointer as second argument named *userp* which is passed as
31the first argument to the curl_formget_callback function.
32
33~~~c
34 typedef size_t (*curl_formget_callback)(void *userp, const char *buf,
35                                         size_t len);"
36~~~
37
38The curl_formget_callback is invoked for each part of the HTTP POST chain. The
39character buffer passed to the callback must not be freed. The callback should
40return the buffer length passed to it on success.
41
42If the **CURLFORM_STREAM** option is used in the formpost, it prevents
43curl_formget(3) from working until you have performed the actual HTTP
44request. This, because first then does libcurl known which actual read
45callback to use!
46
47# EXAMPLE
48
49~~~c
50size_t print_httppost_callback(void *arg, const char *buf, size_t len)
51{
52  fwrite(buf, len, 1, stdout);
53  (*(size_t *) arg) += len;
54  return len;
55}
56
57size_t print_httppost(struct curl_httppost *post)
58{
59  size_t total_size = 0;
60  if(curl_formget(post, &total_size, print_httppost_callback)) {
61    return (size_t) -1;
62  }
63  return total_size;
64}
65~~~
66
67# AVAILABILITY
68
69This function was added in libcurl 7.15.5. The form API is deprecated in
70libcurl 7.56.0.
71
72# RETURN VALUE
73
740 means everything was OK, non-zero means an error occurred
75