Well, what I mean to say is that finally I have a program that compiles
(no small feat for me), that connects to a ZonePlayer, and that even
makes a request (sheesh, that took me ages.) I'm just not getting the
desired response. To be specific: UPnP error 401. Which I believe means
"invalid action".
I assume my POST request for information, stored in XML format, is
incorrect. Here is the data I am sending:
*************************************************
char *PostData =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
" <s:Envelope
s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"
xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
" <s:Body>\n"
" <u:GetAudioInputName
xmlns:u=\"urn:schemas-upnp-org:service:AudioIn:1\" />\n"
" </s:Body>\n"
"</s:Envelope>";
*************************************************
Here is the relevant parts of my code:
*************************************************
// Specify an HTTP server.
if( hSession )
hConnect = WinHttpConnect( hSession, L"10.0.1.136",
1400, 0 );
// Create an HTTP request handle.
if( hConnect )
hRequest = WinHttpOpenRequest( hConnect, L"POST",
L"/AudioIn/Control",
NULL, WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
0);
// Send a request.
if( hRequest )
bResults = WinHttpSendRequest( hRequest,
WINHTTP_NO_ADDITIONAL_HEADERS, 0,
PostData, 0,
0, 0 );
*************************************************
Anyway... from looking at the output of DeviceSpy, it looks like I may
need to include:
SOAPACTION: "urn:schemas-upnp-org:service:AudioIn:1#GetAudioInputName"
Where do I put this? Is this what's causing my 401 error? Has anyone
else enocountered it?
char *ExtraHeader = "SOAPACTION:
\"urn:schemas-upnp-org:service:AudioIn:1#GetAudioInputName\"";
And the HTTP request.... (which is the line the error points to)
WinHttpSendRequest( hRequest, ExtraHeader, 256, PostData, 0, 0, 0 );
I put 256 as the length just so it'd have a bit of padding. I guess
I'll have to figure out how to dynamically figure this out later.
Now I'm back to getting Error 87, which I think is due to an incorrect
string lenth being specified to WinHttpSendRequest. I'm trying to
calculate lengths with:
char PostLength = lstrlen(PostData)*sizeof(TCHAR);
but for some reason that gives me a length of 18, when my XML code to
be POST'd is waay longer (like 200 at a guess.) Can that method handle
escape characters? And seperate lines?
Here's what I need to have in my WinHttpSendRequest statement (from the
MSDN):
pwszHeaders
[in] A pointer to a string that contains the additional headers to
append to the request. This parameter can be
WINHTTP_NO_ADDITIONAL_HEADERS if there are no additional headers to
append.
It seems the POST data is a "pointer to a buffer" (char *postdata =
"post data"; works) but the headers are a "pointer to a string". I
don't know how to make a pointer to a string. God only knows why they
aren't BOTH a "pointer to a buffer". I guess I'll start googling...