Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-14-2008, 02:43 AM   #1
Registered: Jul 2007
Location: /home
Distribution: Debian
Posts: 37

Rep: Reputation: 15
webdav c++ programming

For testing purposes, I was given the task to create an appointment for every user on a microsoft 2007 exchange server.

I started out with a simple program under linux, but after the first message I send I got an "HTTP/1.1 401 Unauthorized" message back.
Looking at traces from other programs I discovered a challenge code has to be send after this message ( you get the same scenario when you use lynx sometimes ).

I searched a while on the internet, found some open source projects that have webdav included, but the code is very unreadable.

An existing tool/program could also be a solution so if anyone has suggestions?
Old 10-14-2008, 08:29 AM   #2
Registered: Jul 2007
Location: /home
Distribution: Debian
Posts: 37

Original Poster
Rep: Reputation: 15
After 6 hours of searching the internet. I found a website with a php script that could generate for example emails:

I modified the script and now it can add appointments. Here's the code:


// Modify the path to this class file as needed.

// Change these values for your Exchange Server.
$exchange_server = "";
$exchange_username = "test";
$exchange_password = "123!test";

// We use Troy's http class object to send the XML-formatted WebDAV request
// to the Exchange Server and to receive the response from the Exchange Server.
// The response is also XML-formatted.
$h = new http();
$h->headers["Content-Type"] = 'text/xml; charset="UTF-8"';
$h->headers["Depth"] = "0";
$h->headers["Translate"] = "f";

$subject = "a" . rand();

// Build the XML request.
// This section must be against the left margin.

$h->xmlrequest = '<?xml version="1.0" encoding="utf-8"?>';
$h->xmlrequest .= <<<END
<D:propertyupdate   xmlns:ns0=""
                    xmlns:ns3="urn:schemas:calendar:" xmlns:D="DAV:">
              <ns1:subject>My New Appointment</ns1:subject>

// IMPORTANT -- The END line above must be completely left-aligned. No white-space.

// The http object's 'fetch' method does the work of sending and receiving the
// request. We use the WebDAV PROPPATCH method to create or update Exchange items.
$url = $exchange_server."/Exchange/test/calendar/".urlencode($subject).".EML";
if (!$h->fetch($url, 0, null, $exchange_username, $exchange_password, "PROPPATCH")) {
  echo "<h2>There is a problem with the http request!</h2>";
  echo $h->log;

// You can print out the response to help troubleshoot.
echo "<pre>".$h->header."</pre><hr />\n";
echo "<pre>".$h->body."</pre><hr />\n";

// Bonus tip! You can automatically open this new draft message for your user by
// formulating an outlook URL. Then either redirect to the URL by uncommenting the
// header line below, or pop the URL in client-side javascript using
#header("Location: outlook:drafts/~".urlencode($subject));

Old 11-11-2008, 02:09 AM   #3
Registered: Jul 2007
Location: /home
Distribution: Debian
Posts: 37

Original Poster
Rep: Reputation: 15
It is also possible to set a location by adding:

$h->xmlrequest .= "              <ns3:location>patio</ns3:location>";
Note that ns3 refers to the schema ns3 (xmlns ns3)


exchange, webdav

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
webdav tszhim Linux - Software 1 05-10-2005 10:02 PM
webdav dummyagain Linux - Software 0 10-14-2004 12:56 AM
WebDAV Questions wolftechmn Linux - Networking 1 04-21-2004 06:06 AM
webdav b_usa Linux - General 1 04-04-2003 05:00 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:06 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration