OK, I've moved on a bit now. Managed to iron out most of the POST I think. Here's the code I've added at the start:
Code:
// UPnP request to be sent via POST in XML format
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>";
// SOAP header required for UPnP request
unsigned char *ExtraHeader = "SOAPACTION: \"urn:schemas-upnp-org:service:AudioIn:1#GetAudioInputName\"";
// Length of UPnP request
char PostLength = lstrlen(PostData)*sizeof(TCHAR);
// Length of SOAP header
char HeaderLength = lstrlen(ExtraHeader)*sizeof(TCHAR);
// Total length
char TotalLength = PostLength + HeaderLength;
// FYI
printf("postlength is %d\n", PostLength);
printf("headerlength is %d\n", HeaderLength);
printf("totallength is %d\n", TotalLength);
(By the way - the SOAP header gave a huge horrible error - assignment of pointer to const unsigned short to pointer to char - until I added the word "unsigned" in front of it. I hope this was the right fix, all I know is that it works.)
Anyway, here's my new HTTP request code:
Code:
// Send a request.
if( hRequest )
bResults = WinHttpSendRequest( hRequest,
ExtraHeader,
HeaderLength,
PostData, PostLength,
PostLength, 0 );
This now returns an error 87, which I beleive may be due to incorrect values of HeaderLength, PostLength and/or TotalLength.
Interestingly enough, when I run my program, with my "FYI" information that prints out the lengths of the header and POST data, this is what I get:
Code:
postlength is 18
headerlength is 70
totallength is 88
Now the 70 value looks about right, and totallength is calculating OK, but I know for a fact that the XML code I'm sending is a lot longer than 18 characters! What am i doing wrong here?
One more question - why do I use "*sizeof(TCHAR)" when figuring out length? I got that code from another sample somewhere.