1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_POSTFIELDSIZE
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_POSTFIELDS (3)
9  - CURLOPT_POSTFIELDSIZE_LARGE (3)
10Protocol:
11  - HTTP
12Added-in: 7.2
13---
14
15# NAME
16
17CURLOPT_POSTFIELDSIZE - size of POST data pointed to
18
19# SYNOPSIS
20
21~~~c
22#include <curl/curl.h>
23
24CURLcode curl_easy_setopt(CURL *handle, CURLOPT_POSTFIELDSIZE, long size);
25~~~
26
27# DESCRIPTION
28
29If you want to post static data to the server without having libcurl do a
30strlen() to measure the data size, this option must be used. When this option
31is used you can post fully binary data, which otherwise is likely to fail. If
32this size is set to -1, libcurl uses strlen() to get the size or relies on the
33CURLOPT_READFUNCTION(3) (if used) to signal the end of data.
34
35If you post more than 2GB, use CURLOPT_POSTFIELDSIZE_LARGE(3).
36
37# DEFAULT
38
39-1
40
41# %PROTOCOLS%
42
43# EXAMPLE
44
45~~~c
46#include <string.h> /* for strlen */
47
48int main(void)
49{
50  CURL *curl = curl_easy_init();
51  if(curl) {
52    const char *data = "data to send";
53
54    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
55
56    /* size of the POST data */
57    curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long) strlen(data));
58
59    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
60
61    curl_easy_perform(curl);
62  }
63}
64~~~
65
66# %AVAILABILITY%
67
68# RETURN VALUE
69
70Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
71