curl-library
Re: using libcurl to invoke WebDAV methods on Exchange
Date: Wed, 21 Dec 2005 22:34:09 +0100 (CET)
On Wed, 21 Dec 2005, Andrew Biggs wrote:
> I gave this another go after upgrading to libcurl/7.15.1 OpenSSL/0.9.7a
> zlib/1.1.4, but unfortunately the problem persists. Any ideas?
Not really. I amused myself by converting it to plain C, building it and
running it against my localhost's Apache (which doesn't understand DAV at all)
and it did indeed get called properly:
< HTTP/1.1 501 Method Not Implemented
< Date: Wed, 21 Dec 2005 21:22:44 GMT
< Server: Apache/2.0.55 (Debian)
< Allow: GET,HEAD,POST,OPTIONS,TRACE
< Content-Length: 293
< Connection: close
< Content-Type: text/html; charset=iso-8859-1
*** write_data has been called: 293 bytes
* Closing connection #0
And for this, I used the program that now looks like this:
#include <curl/curl.h>
#include <stdlib.h>
#include <string.h>
size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp)
{
printf("*** write_data has been called: %d bytes\n", size*nmemb);
return size*nmemb;
}
#define CHECKCC(x) \
if ((cc = x) != CURLE_OK) { \
printf("Failed at line %d with code %d\n", __LINE__, cc); \
exit(1); \
}
int main()
{
CURLcode cc;
const char *url = "http://localhost/";
const char *userpwd = "aspen\\cucsvc:Bould3r";
const char *method = "SEARCH";
struct curl_slist *slist = NULL;
slist = curl_slist_append(slist, "Accept: text/xml");
slist = curl_slist_append(slist, "Depth: infinity");
slist = curl_slist_append(slist, "Content-Type: text/xml");
slist = curl_slist_append(slist, "Connection: Keep-Alive");
const char *postdata =
"<?xml version=\"1.0\"?><D:searchrequest xmlns:D=\"DAV:\" >"
"<D:sql>SELECT \"http://schemas.microsoft.com/repl/contenttag\""
" from SCOPE ('deep traversal of \"/exchange/adb/Calendar/\"') "
"WHERE \"DAV:isfolder\" = True</D:sql></D:searchrequest>\r\n";
CHECKCC(curl_global_init(CURL_GLOBAL_SSL))
CURL *pcurl = curl_easy_init();
CHECKCC(curl_easy_setopt(pcurl, CURLOPT_VERBOSE, 1))
CHECKCC(curl_easy_setopt(pcurl, CURLOPT_URL, url))
CHECKCC(curl_easy_setopt(pcurl, CURLOPT_CUSTOMREQUEST, method))
CHECKCC(curl_easy_setopt(pcurl, CURLOPT_HTTPHEADER, slist))
CHECKCC(curl_easy_setopt(pcurl, CURLOPT_POSTFIELDS, postdata))
CHECKCC(curl_easy_setopt(pcurl, CURLOPT_POSTFIELDSIZE, strlen(postdata)))
CHECKCC(curl_easy_setopt(pcurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC))
CHECKCC(curl_easy_setopt(pcurl, CURLOPT_USERPWD, userpwd))
CHECKCC(curl_easy_setopt(pcurl, CURLOPT_WRITEFUNCTION, write_data))
CHECKCC(curl_easy_perform(pcurl))
curl_slist_free_all(slist);
}
-- Commercial curl and libcurl Technical Support: http://haxx.se/curl.htmlReceived on 2005-12-21