title: HttpSendRequest - POST data not supporting Unicode
body: <p>I'm working on making a C++ agent that will post information (such as the system hostname) back to a central server using HttpSendRequest(). One of the pieces of information that I want it to post back is the OS. I created the following function that will obtain the system hostname.</p>
  
  <pre><code>wstring getOS()
  {
       HKEY key;
       RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_QUERY_VALUE, &amp;key); // Obtains Registry handle
  
       DWORD type;
       wchar_t buffer[MAX_PATH]; // MAX_PATH = 260 - The system hostname should never exceed this value
       DWORD size = sizeof(buffer);
       RegQueryValueEx(key, L"ProductName", NULL, &amp;type, (LPBYTE)&amp;buffer, &amp;size); // Queries Registry key - stores value in "buffer"
       wstring os(buffer); // Converts from C-style character array to wstring
       return os; // Returns wstring to caller
  }
  </code></pre>
  
  <p>This function will obtain the OS using the Registry and store it as a wstring. I then want to pass the returned "os" wstring to the following post() function, but I noticed that you must use a string instead of a wstring for the HTTP POST data. Below is the code for my post() function:</p>
  
  <pre><code>void post()
  {
       HINTERNET hInternetOpen = InternetOpen(userAgent.c_str(), INTERNET_OPEN_TYPE_PROXY, L"http://127.0.0.1:9999", NULL, 0);
       HINTERNET hInternetConnect = InternetConnect(hInternetOpen, host.c_str(), INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
       HINTERNET hHttpOpenRequest = HttpOpenRequest(hInternetConnect, L"POST", file.c_str(), NULL, NULL, NULL, 0, 0);
  
       wstring headers = L"Content-Type: application/x-www-form-urlencoded"; // Content-Type is necessary to POST
  
       string postData = "os="; // Why does this have to be a string and not a wstring?
  
       HttpSendRequest(hHttpOpenRequest, headers.c_str(), headers.length(), (LPVOID)postData.c_str(), postData.size());
  
       InternetCloseHandle(hInternetOpen);
       InternetCloseHandle(hInternetConnect);
       InternetCloseHandle(hHttpOpenRequest);
  }
  </code></pre>
  
  <p>If I try to make "postData" a wstring, I get something that looks like the image below:</p>
  
  <p><a href="https://i.stack.imgur.com/eZSSY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eZSSY.png" alt="HTTP POST data as wstring"></a></p>
  
  <p>Can someone shed some light onto the easiest way to include a wstring as the POST data?</p>