// Notify() sends a POST request to the Subscription's callback URL.
            // DispatchAsync could be used to keep this method from blocking if the server has many subscriptions
            public void Notify()
            {
                try
                {
                    HttpClientRequest req = new HttpClientRequest();
                    req.RequestType = RequestType.Post;

                    // First, resolve the hostname using the ResolveHost method
                    var    parsedUrl        = new UrlParser(SubscriberCallbackUrl);
                    string resolvedHostname = ResolveHost(parsedUrl.Hostname);

                    // Swap in the resolved hostname when setting the target URL of the notification
                    string resolvedUrl = parsedUrl.ToString().Replace(parsedUrl.Hostname, resolvedHostname);
                    req.Url = new UrlParser(resolvedUrl);
                    HttpHeaders headers = new HttpHeaders();
                    headers.SetHeaderValue("Notification-Type", NotificationType);
                    headers.SetHeaderValue("Link", "<" + ResourceUrl + ">, rel=\"Resource\"");
                    req.Header = headers;
                    req.FinalizeHeader();
                    HttpClientResponse res = notifier.Dispatch(req);

                    if (res.Code != 200)
                    {
                        CrestronConsole.PrintLine("Notification to " + resolvedUrl + " not acknowledged");
                    }

                    // Must call Dispose on the HttpClientResponse object to end the http session
                    res.Dispose();
                }
                catch (Exception e)
                {
                    CrestronConsole.PrintLine(e.ToString());
                }
            }
示例#2
0
 public static void InjectQueryString(IOwinContext context)
 {
     if (context.Environment.ContainsKey("owin.RequestQueryString"))
     {
         var existingQs = context.Environment["owin.RequestQueryString"];
         var parser = new UrlParser(existingQs.ToString());
         parser[Constants.AuthorizeRequest.AcrValues] = newAcrValues;
         context.Environment.Remove("owin.RequestQueryString");
         context.Environment["owin.RequestQueryString"] = parser.ToString();
     }
 }