Skip to content

Docs are not clear about zero-byte POST #862

@safinaskar

Description

@safinaskar

I cannot understand from online docs at https://curl.haxx.se/libcurl/c/ how to do zero-byte POST. It seems docs should be fixed. Is the following code ok?

curl_global_init (CURL_GLOBAL_ALL);
CURL *curl_handle = curl_easy_init ();
curl_easy_setopt (curl_handle, CURLOPT_URL, "http://example.com");
curl_easy_setopt (curl_handle, CURLOPT_POSTFIELDSIZE, 0L);
CURLcode code = curl_easy_perform (curl_handle);

Or I should also set CURLOPT_POST or CURLOPT_POSTFIELDS?
Is the following code ok? Does it really perform zero-byte POST?

curl_global_init (CURL_GLOBAL_ALL);
CURL *curl_handle = curl_easy_init ();
curl_easy_setopt (curl_handle, CURLOPT_URL, "http://example.com");
curl_easy_setopt (curl_handle, CURLOPT_POSTFIELDS, NULL); // is this line ok???
curl_easy_setopt (curl_handle, CURLOPT_POSTFIELDSIZE, 0L);
CURLcode code = curl_easy_perform (curl_handle);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions