cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: CURLOPT_POSTFIELDS not working for me

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Thu, 5 Feb 2009 09:50:34 -0800

On Thu, Feb 05, 2009 at 09:13:56AM -0800, Superprops wrote:
> curl_easy_setopt(hcurl, CURLOPT_URL,
> "http://www.mywebsite.com/curltest.php");
> curl_easy_setopt(hcurl, CURLOPT_POSTFIELDS, "testcode=123456789");
> curl_easy_setopt(hcurl, CURLOPT_WRITEFUNCTION, libcurlWriteMemoryCallback);
> curl_easy_setopt(hcurl, CURLOPT_WRITEDATA, (void *)&libcurlchunk);
> curl_easy_setopt(hcurl, CURLOPT_USERAGENT, "libcurl-agent/1.0");
>
> This returns "failure"
>
> if I eliminate the CURLOPT_POSTFIELDS option setting changing my c code to:
>
> curl_easy_setopt(hcurl, CURLOPT_URL,
> "http://www.mywebsite.com/curltest.php?testcode=123456789");
> curl_easy_setopt(hcurl, CURLOPT_WRITEFUNCTION, libcurlWriteMemoryCallback);
> curl_easy_setopt(hcurl, CURLOPT_WRITEDATA, (void *)&libcurlchunk);
> curl_easy_setopt(hcurl, CURLOPT_USERAGENT, "libcurl-agent/1.0");
>
> it returns "success with testcode = 123456789"
>
> Can anyone tell me what I might be doing wrong ?

The first snippet does a POST request while the second does a GET request.
If you set the CURLOPT_HTTPGET after the CURLOPT_POSTFIELDS in the first
case, you should get the same results.

>>> Dan

-- 
http://www.MoveAnnouncer.com              The web change of address service
          Let webmasters know that your web site has moved
-------------------------------------------------------------------
List admin: http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-users
FAQ:        http://curl.haxx.se/docs/faq.html
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2009-02-05