If using PEP2, have you tried using the Philips HTTP library? Otherwise you will have to encode your parameter string.
What you write to socket will be something like this (4 lines total and you may need to use Javascript url encoding to get this working.) See this.
[Link: stackoverflow.com][Line 1]GET /data_request?id=lu_action&output_format=xml&DeviceNum=3&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1 HTTP 1.0\r\n
[Line 2]host:192.168.0.151\r\n
[Line 3]\r\n
[Line 4]\r\n
So, where you have a single function which writes command + '\r\n' you need to actually build your string as above and send that. Note that if you choose to use the function you have, you can build a command with only the first 3 lines and call the function with that.
Thank you for your help with this code. I will have to do some more reading up on this to better understand your instructions. I will report back with outcome.