HTTP Communication

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

To secure the potentially sensitive information published in the course of a Unified Communications session, the Communicator Web Access Server is configured for HTTPS communication by default. This means that your client application must be able to validate a Communicator Web Access Server certificate at the time you logon. To do this you must add the following logic to your project:

  • Add the following code at the top of your class source code file.

    using System.Security.Cryptography.X509Certificates; 
    using System.Net.Security;
    
  • In your class constructor add the following code.

    System.Net.ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(RemoteCertificateValidationCallbackHandler);
    
  • You must also create a callback function as follows.

    public bool RemoteCertificateValidationCallbackHandler(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
    {
    return true;
    }
    

You implement HTTP communication by using any of these three objects:

  • XMLHttpRequest for JavaScript clients.

  • IXMLHttpRequest (for Internet Explorer version 6.0 and earlier) interface using the Microsoft ActiveX scripting object, for JavaScript clients or other scripting clients.

  • HttpWebRequest for either stand-alone Unified Communications service clients or Web clients written in a Microsoft .NET language.

HTTP Request in C#

The following C# code snippet shows a synchronous HTTP GET request using HttpWebRequest.

String url = ...         // Some URL
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

request.Method = "GET";
request.Accept = "*/*";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50215)";
request.ContentType = "application/x-www-form-urlencoded";
request.Timeout = 1000 * 60;
request.Headers.Add("CWA-Ticket", this.authTicket);
request.AuthenticationLevel = AuthenticationLevel.None; request.ClientCertificates.Add(new X509Certificate());
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

The following C# code snippet shows a synchronous HTTP POST request.

byte[] messageBody = ... // Some data
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
Request.Method = "POST";
request.Accept = "*/*";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50215)";
request.ContentType = "application/x-www-form-urlencoded";
request.Timeout = 1000 * 60;
request.Headers.Add("CWA-Ticket", this.authTicket);
Stream reqStream = request.GetRequestStream();
request.AuthenticationLevel = AuthenticationLevel.None;
request.ClientCertificates.Add(new X509Certificate());
reqStream.Write(messageBody, 0, messageBody.Length);
reqStream.Close();
reqStream = null;
HTTPWebResponse response = (HttpWebResponse)request.GetResponse();

HTTP Request in JavaScript

The following JavaScript code snippet shows a synchronous HTTP GET request made from Internet Explorer version 6.0 and earlier.

var url = "https://www.contoso.com";
httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
var isAsync = false;
httpRequest.Open("GET", url, isAsync);

httpRequest.setRequestHeader("Accept", "*/*");
httpRequest.setRequestHeader("UserAgent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50215)");
httpRequest.setRequestHeader("Timeout", 1000*60);
httpRequest.setRequestHeader("CWA-Ticket", this.authTicket);

HttpRequest.Send();
if (_httpRequest.Status == 200)
{
    var responseText = HttpRequest.ResponseText;
}
else
{
   // report error
}

The following JavaScript code snippet shows an asynchronous HTTP POST request made from such browsers as Mozilla FireFox or Apple Safari.

var url = "https://www.contoso.com";
var data = "<cwaRequests xmlns= "http://schemas.microsoft.com/2006/09/rtc/cwa">...</cwaRequests>";
var httpRequest = new XMLHttpRequest();
var isAsync = true;


httpRequest.open("POST", url, isAsync);
httpRequest.setRequestHeader("Accept", "*/*");
httpRequest.setRequestHeader("UserAgent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50215)");
httpRequest.setRequestHeader("ContentType", "application/x-www-form-urlencoded");
httpRequest.setRequestHeader("Timeout", 1000*60);
httpRequest.setRequestHeader("CWA-Ticket", this.authTicket);


httpRequest.onreadystatechange = ReadyStateChanged;
httpRequest.send(data);


function ReadyStateChanged()
{
   if (httpRequest.readyState == 4)
   {
      if (httpRequest.Status == 200)
      {
         var responseText = httpRequest.ResponseText;
      }
      else
      {
         // report error
      }
   }
}

See Also

Concepts

About Unified Communications AJAX SDK

Unified Communications AJAX API Reference