WinHttpRequest with Asia characters.

I get some example code from msdn and it work properly always except when Asia

characters involved.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
BOOL  bResults = FALSE;
        HINTERNET hSession = NULL,
        hConnect = NULL,
        hRequest = NULL;

        // Use WinHttpOpen to obtain a session handle.
        hSession = WinHttpOpen(  L"Pro Name", 
            WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
            WINHTTP_NO_PROXY_NAME, 
            WINHTTP_NO_PROXY_BYPASS, 0);

        // Specify an HTTP server.
        if (hSession)
            hConnect = WinHttpConnect( hSession, L"Server Addr",
            INTERNET_DEFAULT_HTTP_PORT, 0);
        
        CString strObject = L"Request Text";  
        //if strObject is Chinese      characters, it will be some 
        //gibberish code when I receive it in my server.

        // Create an HTTP Request handle.
        if (hConnect)
            hRequest = WinHttpOpenRequest( hConnect, L"GET", strObject , 
            NULL, WINHTTP_NO_REFERER, 
           WINHTTP_DEFAULT_ACCEPT_TYPES, WINHTTP_FLAG_ESCAPE_DISABLE_QUERY );

        // Send a Request.
        if (hRequest) 
            bResults = WinHttpSendRequest( hRequest, 
            WINHTTP_NO_ADDITIONAL_HEADERS, 0,
            WINHTTP_NO_REQUEST_DATA, 0, 
            0, 0);

        // PLACE ADDITIONAL CODE HERE.

        // Report any errors.
        if (!bResults)
            printf("Error %d has occurred.\n",GetLastError());

        // Close any open handles.
        if (hRequest) WinHttpCloseHandle(hRequest);
        if (hConnect) WinHttpCloseHandle(hConnect);
        if (hSession) WinHttpCloseHandle(hSession);


if strObject cantain some Aisa characters it will be gibberish code when I get it from IIS.

what Can I do to solve this issue?

In addition: if I implemented it with WinInet instead of WinHTTP, it works.

Thanks,

Levi
Last edited on
Topic archived. No new replies allowed.