因此,我將一些數據從我的C++桌面應用程序發佈到我的服務器(PHP腳本)。發送或接收錯誤嗎?沒有發送完整消息或沒有正確解碼消息
並非所有的發佈數據都被服務器接收到。你認爲這個錯誤發生在哪裏?在服務器端解碼(UTF-8)還是客戶端傳輸?
C++代碼:注意它的Unicode。如果我發送ASCII腳本接收/解碼後整體數據串:
static TCHAR hdrs[] =
_T("Content-Type: application/x-www-form-urlencoded; charset=UTF-8\0\0");
static TCHAR frmdata[] =
_T("name=John+Doe&auth=abc\0\0"); // use 2 null chars just incase
static LPSTR accept[2] = { "*/*", NULL };
HINTERNET hSession = InternetOpen(_T("MyAgent"),
INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
// error checking removed but none of these fail
HINTERNET hConnect = InternetConnect(hSession, _T("mydomain.com"),
INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
HINTERNET hRequest = HttpOpenRequest(hConnect, _T("POST"),
_T("upload.php"), NULL, NULL, (LPCWSTR*)&accept, INTERNET_FLAG_NO_CACHE_WRITE, 1);
HttpSendRequest(hRequest, hdrs, _tcslen(hdrs), frmdata, _tcslen(frmdata));
// The above function returns true and I query the response code and its HTTP 200 ok so sending is working
簡單的PHP腳本:
$data = file_get_contents("php://input");
file_put_contents("post.txt", $data); // outputs "name=John+D" so its missing text
// To make things even more confusing
echo mb_detect_encoding($data); // outputs ASCII!!!???
古怪,如果我爲ASCII腳本接收/發送解碼後整體數據
static char hdrs[] =
_T("Content-Type: application/x-www-form-urlencoded; charset=UTF-8\0\0");
static char frmdata[] =
_T("name=John+Doe&auth=abc\0\0");
static LPCSTR accept[2] = { "*/*", NULL };
...
HttpSendRequestA(hRequest, hdrs, strlen(hdrs), frmdata, strlen(frmdata));
// The above function returns true and I query the response code and its HTTP 200 ok so sending is working
With ASCII post.txt contains name=John+Doe&auth=abc
。那麼錯誤會在哪裏發生?是不是發送完整的帖子字符串或者PHP腳本沒有正確處理unicode?
'_T
幾個例子(」 ...的charset = UTF-8" );' - ,一旦是一個謊言,你'#定義_UNICODE'。您需要了解字符編碼以及這些通用文本映射的內容(請參見[Ansi-和Wide-character函數](http://stackoverflow.com/documentation/winapi/2450/ansi-and-wide-character-功能/ 8085 /引入#噸= 201607250227403955238))。 – IInspectable
@IInspectable是的,那只是一個測試。即使沒有指定字符集,它也會失敗。 –