private HttpResponse ExecuteHttpRequestBackground()
        {
            // see -
              //  http://stackoverflow.com/questions/4982765/json-call-with-c-sharp
              //  http://msdn.microsoft.com/query/dev11.query?appId=Dev11IDEF1&l=EN-US&k=k%28System.Net.HttpWebRequest.ContentType%29;k%28TargetFrameworkMoniker-.NETFramework,Version%3Dv4.5%29;k%28DevLang-csharp%29&rd=true

              Log.Trace("ExecuteHttpRequest - uri: " + _uri + " , RequestMethod: " + _requestMethod + " , ContentType: " + _contentType + " , TimeOutMS: " + _timeoutMS.ToString() + " , Body: " + _body);

              HttpResponse response = new HttpResponse("", HttpStatusCode.Unused);

              try
              {
            var webRequest = (HttpWebRequest)WebRequest.Create(_uri);
            webRequest.Method       = _requestMethod;
            webRequest.ContentType  = _contentType; // "text/xml" or "application/json" or "application/x-www-form-urlencoded"
            webRequest.Timeout      = _timeoutMS;
            if (_credentials != null)
              webRequest.Credentials  = _credentials;

            // POST or PUT with a body
            if ((_requestMethod.ToUpper() == "POST" || _requestMethod.ToUpper() == "PUT") &&
              !String.IsNullOrEmpty(_body))
            {
              //ASCIIEncoding encoding = new ASCIIEncoding();
              //Byte[] buffer = Encoding.UTF8.GetBytes(body);
              //webRequest.ContentLength = buffer.Length;
              //webRequest.UseDefaultCredentials = true;
              //Stream requestStream = webRequest.GetRequestStream();
              //requestStream.Write(buffer, 0, buffer.Length);

              using (var requestWriter = new StreamWriter(webRequest.GetRequestStream()))
              {
            requestWriter.Write(_body);
              }
            }

            var webResponse = (HttpWebResponse)webRequest.GetResponse();
            using (var streamReader = new StreamReader(webResponse.GetResponseStream()))
            {
              response.Text = streamReader.ReadToEnd();
              response.StatusCode = webResponse.StatusCode;
            }

            // close the Stream object
            webResponse.Close();
              }
              catch (Exception ex)
              {
            Log.TraceException("ExecuteHttpRequest", ex);
            response.Exception = ex.Message;
            return response;
              }

              return response;
        }
 void worker_DoWork(object sender, DoWorkEventArgs e)
 {
     Response = ExecuteHttpRequestBackground();
 }
 public HttpResponse ExecuteHttpRequest()
 {
     HttpResponse response = new HttpResponse("", HttpStatusCode.Unused);
       using (new WaitCursor())
       {
     response = ExecuteHttpRequestBackground();
       }
       return response;
 }