curl_easy_perform, how to keep the result?


 
Thread Tools Search this Thread
Top Forums Programming curl_easy_perform, how to keep the result?
# 1  
Old 05-21-2009
curl_easy_perform, how to keep the result?

hi,

i run the code below, it return me correct result and message.
but may i know how do i keep the result "1 Success" in a variable?
is it i need to using the WRITEFUNCTION and WRITEDATA?
may i know how to do?
could anyone can give me the source for keep the result in a variable?

Thanks

Code:
#include <stdio.h>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
#include <string.h>
#include <stdlib.h>

int main(void)
{
char *abc;
int intA;
 CURL *curl;
  CURLcode res;
  curl = curl_easy_init();

 if(curl) {
    /* First set the URL that is about to receive our POST. This URL can
       just as well be a https:// URL if that is what should receive the
       data. */
    curl_easy_setopt(curl, CURLOPT_URL, "https://domain.com/jsp/filename.jsp");

    /* Now specify the POST data */
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "param1=value1&param2=value2");

    /* some servers don't like requests that are made without a user-agent
     field, so we provide one */
  curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0");
curl_easy_setopt(curl, CURLOPT_READDATA, abc);
    /* Perform the request, res will get the return code */
    res = curl_easy_perform(curl);

printf("CURLCODE := %d \n ",res);
 
    /* always cleanup */
    curl_easy_cleanup(curl);

}
  return 0;
}

OUTPUT
1 Success
CURLCODE := 0

Last edited by otheus; 05-25-2009 at 11:42 AM.. Reason: code tags
# 2  
Old 05-25-2009
From the manpage at http://curl.haxx.se/libcurl/c/curl_easy_perform.html:
Quote:
Return Value: 0 means everything was ok, non-zero means an error occurred as <curl/curl.h> defines. If the CURLOPT_ERRORBUFFER was set with curl_easy_setopt there will be a readable error message in the error buffer when non-zero is returned.
So 0 means success, and the output you are seeing might be some kind of debugging that's enabled so that the errorbuffer is output. Close or redirect stderr to see if it goes away.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to compare the current result with previous line result.?

Hi Gurus, I have requirement to compare current result with previous reuslt. The sample case is below. 1 job1 1 1 job2 2 1 job3 3 2 job_a1 1 2 job_a2 2 2 job_a3 3 3 job_b1 1 3 job_b2 2 for above sample file, GID is group ID, for input line, the job run... (1 Reply)
Discussion started by: ken6503
1 Replies

2. Shell Programming and Scripting

How can I get the required result?

Hi, guys. I have a question. Please help me~ I got an text, recording the weather reports. It is the Attachment "Weather Forcast_original.txt" I want to get the required result like the attachment "Weather Forcast_formatted.txt" I thought about the loop, the conditions, but I'm surely... (3 Replies)
Discussion started by: franksunnn
3 Replies

3. Shell Programming and Scripting

Strange result

Hi, I have following codes which looks ok: $ string1="123456789 abc2" $ string2="abc" $ position_of_string2=`expr index "$string1" "$string2"` $ echo $position_of_string2 $ 11however, when string2="abc2", it gives me the following result: $ string1="123456789 abc2" $... (5 Replies)
Discussion started by: littlewenwen
5 Replies

4. UNIX for Dummies Questions & Answers

Help me in getting the desired result

Hi All, I have input file which is pipe delimited A | 1 B | 2 c | 3I need output of displaying total number of lines in a file as last column. A | 1 | 3-----total number of linesin file. B | 2 | 3 c | 3 | 3 (9 Replies)
Discussion started by: pravinashwin
9 Replies

5. UNIX for Dummies Questions & Answers

what is the result of this?

ls -A $variable (2 Replies)
Discussion started by: prathimahsc
2 Replies

6. UNIX for Dummies Questions & Answers

what is the result of this?

if ] (1 Reply)
Discussion started by: prathimahsc
1 Replies

7. Shell Programming and Scripting

Get execute result of su

I wrote a shell script. su user << EOF some commands result=$? EOF echo $result Other program determined by $result It outputs nothing. How to pass the variable 'result' "inside su" to "outside su"? (5 Replies)
Discussion started by: uativan
5 Replies

8. UNIX for Dummies Questions & Answers

display the result of wc -l with words before and after the result

hello showrev -p | wc -l returns: 381 What to do in case I want to have this output: number of lines returned by showrev -p is: 381 thx (3 Replies)
Discussion started by: melanie_pfefer
3 Replies

9. Shell Programming and Scripting

Outputting formatted Result log file from old 30000 lines result log<help required>

Well I have a 3000 lines result log file that contains all the machine data when it does the testing... It has 3 different section that i am intrsted in 1) starting with "20071126 11:11:11 Machine Header 1" 1000 lines... "End machine header 1" 2) starting with "20071126 12:12:12 Machine... (5 Replies)
Discussion started by: vikas.iet
5 Replies

10. Shell Programming and Scripting

sftp result

Hi, I have a sftp account to another server, from which I need to find out all the files match "*.abc.*.xml" pattern in a certain directory. I have a batchfile as follows cd /tmp ls -l *.abc.*.xml quit then I run output=`/usr/local/bin/sftp -B $batchfile $USER@$HOST` the result looks... (2 Replies)
Discussion started by: mpang_
2 Replies
Login or Register to Ask a Question