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