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