Question

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";
Était-ce utile?

La solution

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

Autres conseils

For others who land here and wonder how UPNP Subscriptions work. This is a very simplified usage example.

I'll use netcat to open a port and respond to incoming events with an HTTP 200. To initialize the connection I'll use curl. This works on an Ubuntu 19.10 with preinstalled curl and nc.

curl -v http://192.168.1.47:58424/RenderingControl/evt -H "CALLBACK: <http://192.168.1.32:1234>" -H "NT: upnp:event" -H "TIMEOUT: Second-1800" -X SUBSCRIBE

Here http://192.168.1.47:58424/RenderingControl/evt is the device specific URL to register to the event. The CALLBACK header specifies the port and IP address on which our netcat server is running. It is important here to add http:// as mentioned before.

The server that listens and sends the HTTP OK is run with the following:

while true; do echo -e 'HTTP/1.1 200 OK\r\nContent-length: 0\r\nConnection: close\r\n\r\n' | nc -l 1234; done
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top