curl-library
What am I doing wrong?
From: Pedro Medeiros <pzilla_at_yawl.com.br>
Date: Tue, 9 Oct 2001 10:50:39 +0000
Date: Tue, 9 Oct 2001 10:50:39 +0000
I'm trying to reuse a curl connection, but the post forms I send get
corrupted on apache. Here is the code:
curltest.c:
---- #include <stdio.h> #include <curl/curl.h> int main(int argc, char argv[]) { struct HttpPost *first, *last; CURL *curl; CURLcode ccode; curl_global_init(CURL_GLOBAL_NOTHING); curl = curl_easy_init(); if (!curl) { fprintf(stderr, "curl_easy_init error!\n"); exit(1); } curl_easy_setopt(curl, CURLOPT_URL, "localhost/test.php"); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); first = (void*)0; last = (void*)0; curl_formadd(&first, &last, CURLFORM_COPYNAME, "abcdef", CURLFORM_COPYCONTENTS, "12345", CURLFORM_END); curl_formadd(&first, &last, CURLFORM_COPYNAME, "ghijkl", CURLFORM_COPYCONTENTS, "67890", CURLFORM_END); curl_easy_setopt(curl, CURLOPT_HTTPPOST, first); ccode = curl_easy_perform(curl); if (ccode) { fprintf(stderr, "curl_easy_perform error\n"); exit(1); } curl_formfree(first); curl_easy_setopt(curl, CURLOPT_URL, "localhost/test.php"); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); curl_easy_setopt(curl, CURLOPT_HTTPPOST, first); first = (void*)0; last = (void*)0; curl_formadd(&first, &last, CURLFORM_COPYNAME, "abcdef", CURLFORM_COPYCONTENTS, "A", CURLFORM_END); curl_formadd(&first, &last, CURLFORM_COPYNAME, "ghijkl", CURLFORM_COPYCONTENTS, "0", CURLFORM_END); curl_easy_setopt(curl, CURLOPT_HTTPPOST, first); ccode = curl_easy_perform(curl); if (ccode) { fprintf(stderr, "curl_easy_perform error\n"); exit(1); } curl_easy_cleanup(curl); curl_global_cleanup(); } ---- and test.php: ---- <? foreach ($HTTP_POST_VARS as $k => $v) { print "[$k] = [$v]\n"; } ?> ---- The output: [abcdef] = [12345] [ghijkl] = [67890] [abcdef@] = [A @ @%] [ghijkl@] = [0 @ @] Second request got corrupted. The same thing happened running Linux and FreeBSD.Received on 2001-10-09