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