When HTTP posting data; if I use std::wstring as a parameter not all the text is posted. But if I use a standard TCHAR array then all the text is posted. Why is this happening and how can I keep using the std::wstring?
// wont compile unless cast to LPVOID and not all data is sent. HttpSendRequest(hRequest, hdrs, -1, (LPVOID)fData.c_str(), fData.size()); // successfully sends all fData text TCHAR s[1024] = {0}; _tcscpy(s, fData.c_str()); HttpSendRequest(hRequest, hdrs, -1, s, sizeof(s));
LPVOID, ie, void pointer. A void pointer can be any type.HttpSendRequestshould usefData.size() * 2if that'sstd::wstringT*converts implicitly tovoid*, no cast required. So presumably this is aconst_castthen. You could have included that information: the comment indicated wrong type.fData"as is"?HttpSendRequestdoes not perform any translation of that parameter, it just sends the raw bytes, so you are assuming that on the other end there's somebody who is expecting to receive UTF-16 data, which is a bit unusual in the HTTP world.