Thread: Winhttpopenrequest encoding issue

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    3

    Winhttpopenrequest encoding issue

    I noticed that '_' (underscore) characters are being converted to ' ' (whitespace) in my URL. I'm not sure what I should do to get around this issue. Also, if someone knows of any MS APIs that do modified base64 encoding, I'd be very grateful if they told me.

    Thanks so much in advance.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    WinHttpOpenRequest function
    WinHTTP Sessions Overview
    Well it's generally a good idea to actually show some code, so that we have some idea of the context in which it is being used, and the many optional flags that these functions support.

    Saying "I tried x and it didn't work" doesn't tell us anything useful apart from "I have a problem".
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    3
    Thanks for the suggestion Salem.
    hRequest = WinHttpOpenRequest( hConnect,
    A2W(httpMethod),
    A2W(relativeURI),
    L"HTTP/1.1",
    WINHTTP_NO_REFERER,
    WINHTTP_DEFAULT_ACCEPT_TYPES,
    WINHTTP_FLAG_SECURE);

    is what my call looks like, where relativeURI is something like
    bbb83Dk-UT5tOZibYBJZc3tOak0-prigwn_3pCh1YTw1
    The underscore is converted to a space.

    Also if I wanted to convert
    bbb83Dk+UT5tOZibYBJZc3tOak0+prigwn/3pCh1YTw1=
    to the above modified base64 encoded format, I don't know what MS API to use for a native C++ app. I cannot use any managed code and I care about multi byte chars. I'm loath to write one unless I'm sure there's no other way out.

  4. #4
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    Code:
    #include <windows.h>
    #include <winhttp.h>
    #pragma comment(lib, "winhttp.lib")
    int main()
    {
        HINTERNET hSession = WinHttpOpen(L"Test", WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0);
        if(hSession)
        {
            HINTERNET hCon = WinHttpConnect(hSession, L"www.google.com", INTERNET_DEFAULT_HTTP_PORT, 0);
            if(hCon)
            {
                HINTERNET hRequest = WinHttpOpenRequest(
                    hCon,
                    L"GET",
                    L"bbb83Dk-UT5tOZibYBJZc3tOak0-prigwn_3pCh1YTw1",
                    L"HTTP/1.1",
                    WINHTTP_NO_REFERER,
                    WINHTTP_DEFAULT_ACCEPT_TYPES,
                    0
                );
                if(hRequest)
                {
                    WinHttpSendRequest(hRequest, NULL, 0, NULL, 0, 0, 0);
                    WinHttpCloseHandle(hRequest);
                }
                WinHttpCloseHandle(hCon);
            }
            WinHttpCloseHandle(hSession);
        }
        return 0;
    }
    Quote Originally Posted by wireshark
    GET /bbb83Dk-UT5tOZibYBJZc3tOak0-prigwn_3pCh1YTw1 HTTP/1.1
    Connection: Keep-Alive
    User-Agent: Test
    Host: www.google.com
    Whatever your problem is, it's not an intrinsic behaviour of the function.

  5. #5
    Registered User
    Join Date
    Oct 2011
    Posts
    3
    Gaaa. Never trust another's logging capabilities. I don't know why I didn't try this myself. Any API that does modified base64 encoding though?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Encoding
    By /dev/bag in forum Linux Programming
    Replies: 1
    Last Post: 06-05-2011, 02:08 PM
  2. bandwidth issue / network issue with wireless device communication
    By vlrk in forum Networking/Device Communication
    Replies: 0
    Last Post: 07-05-2010, 11:52 PM
  3. html encoding issue
    By Checker1977 in forum Tech Board
    Replies: 8
    Last Post: 12-18-2008, 05:18 PM
  4. XML encoding issue
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 05-16-2008, 05:21 AM
  5. URL Encoding
    By nickname_changed in forum C# Programming
    Replies: 2
    Last Post: 03-13-2004, 03:22 AM

Tags for this Thread