cURL / Mailing Lists / curl-library / Single Mail

curl-library

Libcurl POST XML file URGENT help

From: Addanki Venkat <venkat_at_wideareasystems.com>
Date: Tue, 12 Aug 2008 15:30:01 -0400

 

I am new to libcurl and I am trying to POST XML file (size up to 500 bytes).
I am giving the code below.

 

When I look at ethereal trace I don't see any data only header will be
there, I tried with sample string as length 500 considered as big. Still it
has same problem. I am not able to send even single character as data along
with HTTP1.1 POST.

 

I stuck with this problem and no clue since yesterday evening. I really
appreciate any one can give quick solution.

 

Thanks in advance,

 

Here is code chunk,

 

bool CControlStream::OpenCURLSession()

{

                curl_global_init(CURL_GLOBAL_ALL);

                m_pCURL = curl_easy_init();

 

                if (m_pCURL)

                {

                                // HTTP Authentication

                                curl_easy_setopt(m_pCURL, CURLOPT_HTTPAUTH,
CURLAUTH_DIGEST);

                                curl_easy_setopt(m_pCURL, CURLOPT_USERPWD,
m_strUserPassword.c_str());

 

                                // 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(m_pCURL, CURLOPT_URL,
m_strURL.c_str());

 

                                return true;

                }

                else

                                return false;

}

 

void CControlStream::CloseCURLSession()

{

                if (m_pCURL)

                {

                                curl_easy_cleanup(m_pCURL);

                }

}

 

 

 

 

                OpenCURLSession();

                CURLcode res;

                ostringstream xrStream;

                m_pXmlRes.memory = NULL;

                m_pXmlRes.size = 0;

 

                LPDCS_ConferenceData pConfData
=(LPDCS_ConferenceData)pConference->pData;

 

                char sTmp[15];

                char test[30];

                char curlError[CURL_ERROR_SIZE+1];

                sprintf(sTmp,"%d",(pConfData->generic).ConferenceID.rid);

                CString sConfName = ((pConfData->generic).sResource).szName;

 

                m_MGCXmlParser.fnConfStartXmlMsg(sConfName, sTmp, xrStream);

 

                strcpy(test, "My Test libcurl Program");

 

                struct curl_slist *headers=NULL;

                headers = curl_slist_append(headers, "Content-Type:
text/xml");

 

                curl_easy_setopt(m_pCURL, CURLOPT_POST, 1);

 

                std::string strDoc = "xmldoc=" + xrStream.str();

 

                std::cout << strDoc.c_str() << std::endl;

                //curl_easy_setopt(m_pCURL, CURLOPT_POSTFIELDS, (char
*)strDoc.c_str());

                curl_easy_setopt(m_pCURL, CURLOPT_POSTFIELDS, (char *)test);

 

                /* we pass our 'chunk' struct to the callback function */

                curl_easy_setopt(m_pCURL, CURLOPT_WRITEDATA, (void
*)&m_pXmlRes);

 

                curl_easy_setopt(m_pCURL, CURLOPT_HEADER, 0 );

 

                curl_easy_setopt(m_pCURL, CURLOPT_WRITEFUNCTION,
libcurlCallback);

 

                curl_easy_setopt(m_pCURL, CURLOPT_ERRORBUFFER, curlError);

                curl_easy_setopt(m_pCURL, CURLOPT_NOPROGRESS, 1);

 

                /* pass our list of custom made headers */

                curl_easy_setopt(m_pCURL, CURLOPT_HTTPHEADER, headers);

 

                std::cout << strDoc.size() << std::endl;

                /* set the size of the postfields data */

                //curl_easy_setopt(m_pCURL, CURLOPT_POSTFIELDSIZE,
strDoc.size());

 

 

                /* Perform the request, res will get the return code */

                res = curl_easy_perform(m_pCURL);

 

                curl_slist_free_all(headers); /* free the header list */

 

                if(m_pXmlRes.size)

                {

                                ExtractTokens(m_pXmlRes);

                                free(m_pXmlRes.memory);

                }

 

                CloseCURLSession();

                return true;
Received on 2008-08-12