cURL / Mailing Lists / curl-library / Single Mail

curl-library

POST using CURLOPT_READFUNCTION

From: Toshiyuki Maezawa <toshiyuki.maezawa_at_fujixerox.co.jp>
Date: Mon, 18 Apr 2005 17:22:37 +0900 (JST)

Hi,

I try to post data using a read callback that is specified by
CURLOPT_READFUNCTION.

My sample program works, but "Expect: 100-continue" header is not
added in a POST request packet. My understanding is that it is
automatically added when CURLOPT_POST is used.

Is this my misunderstanding or a bug?

Here is my sample code:

---
#include <curl/curl.h>
typedef struct {
	char *buf;
	int len;
	int pos;
} readarg_t;
size_t readcb(void *ptr, size_t size, size_t nitems, void *stream)
{
	readarg_t *rarg = (readarg_t *)stream;
	int len = rarg->len - rarg->pos;
	if (len > size * nitems)
		len = size * nitems;
	memcpy(ptr, rarg->buf + rarg->pos, len);
	rarg->pos += len;
	printf("readcb: %d bytes\n", len);
	return len;
}
int main(int argc, char *argv[])
{
	CURL *curl;
	CURLcode cc;
	char postdata[2048];
	readarg_t rarg;
	memset(postdata, 'a', sizeof(postdata));	/* dummy data */
	rarg.buf = postdata;
	rarg.len = sizeof(postdata);
	rarg.pos = 0;
	if ((curl = curl_easy_init()) == NULL)
		exit(1);
	curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
	curl_easy_setopt(curl, CURLOPT_URL, "http://xxx.xxx.xxx.xxx/");
	curl_easy_setopt(curl, CURLOPT_POST, 1);
	curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, rarg.len);
	curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
#if 0
	/* this works, but "Expect: 100-continue" is not added */
	curl_easy_setopt(curl, CURLOPT_READFUNCTION, readcb);
	curl_easy_setopt(curl, CURLOPT_READDATA, &rarg);
#else
	/* this works fine */
	curl_easy_setopt(curl, CURLOPT_POSTFIELDS, rarg.buf);
#endif
	cc = curl_easy_perform(curl);
	curl_easy_cleanup(curl);
	return 0;
}
---
Thanks
Received on 2005-04-18