Search code examples
c++winapiwininet

HttpSendRequest not posting correct


I am making a simple POST request using WinInet to an apache web server. I encode the data using base 64. The problem is that, every + character gets replaced by space character.

Why is that and how can I make correct POST request.

hInternet = InternetOpen(NULL, INTERNETOPENTYPEPRECONFIG, NULL, NULL, 0);
if (hInternet)
{
    hConnect = InternetConnect(hInternet, szDomain, INTERNETDEFAULTHTTPPORT, NULL, NULL, INTERNETSERVICEHTTP, 0, dwTmp);
    if (hConnect)
    {
        hRequest = HttpOpenRequest(hConnect, szPost, szExfiltrationURL, NULL, NULL,(char *)accept, INTERNETFLAGNOCACHEWRITE | INTERNETFLAGNOCOOKIES | INTERNETFLAGNOUI | INTERNETFLAGRELOAD, 0);
        if (hRequest)
        {
            HttpSendRequest(hRequest, headers, lstrlen(headers), buffer, buflen);
            InternetCloseHandle(hRequest);
        }

        InternetCloseHandle(hConnect);
    }

    InternetCloseHandle(hInternet);
}

Solution

  • From W3

    "Within the query string, the plus sign is reserved as shorthand notation for a space:

    Source: "http://www.w3.org/Addressing/URL/4_URI_Recommentations.html"