Search code examples
c#http-headershttprequestupnp

How to subscribe to UPnP events


This should really be a simple HttpRequestMessage question for most. I'm trying to send a subscription request to a UPnP device as described in section 4.1.2 of the UPnP Device Architecture doc and the message I need to send is supposed to look like the following:

SUBSCRIBE publisher path HTTP/1.1
HOST: publisher host:publisher port  
USER-AGENT: OS/version UPnP/1.1 product/version  
CALLBACK: <delivery URL>  
NT: upnp:event  
TIMEOUT: Second-requested subscription duration 

obviously most of this is pretty straight forward. There are a few items I have questions on because my current method does not work. I get a NotFound returned from the server.

Is the request line SUBSCRIBE publisher path HTTP/1.1 the same as when I create the WebRequest (WebRequest.Create(...)) or is there property somewhere I can set?

Is SUBSCRIBE the HttpMethod in this case or is this a Get, POST, PUT etc?

Here's the current request code:

var request = WebRequest.Create(new Uri(eventUri)) as HttpWebRequest;

request.Method = "SUBSCRIBE";
request.UserAgent = "MyTab/1.0 UPnP/1.1 TestApp/1.0";
request.Headers["CALLBACK"] = "<" + hostname.DisplayName + ":8088>";
request.Headers["NT"] = "upnp:event";
request.Headers["TIMEOUT"] = "Second-300";

Solution

  • looks like I had it all correct, except I forgot to append the http:// to the callback url.