kk33 0 Newbie Poster

Hi, I got a problem in my winttp code which is connecting to the URL successfully but not able to POST the data to the the server, here is my main part of the code

hSession = WinHttpOpen(L"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12", 
                                    WINHTTP_ACCESS_TYPE_NO_PROXY,
                                    WINHTTP_NO_PROXY_NAME, 
                                    WINHTTP_NO_PROXY_BYPASS, WINHTTP_FLAG_ASYNC);

if (hSession)
if (!WinHttpSetTimeouts( hSession, 50000, 50000, 50000,50000))
            printf( "Error %u in WinHttpSetTimeouts.\n", GetLastError());




wchar_t parameters[] = L"user=zzzz&password=xxx";

wchar_t objname[] = L"/profile/login";

DWORD dwLen = wcslen(parameters) * 2 ;



if (hSession)
        hConnect = WinHttpConnect( hSession,L"www.website.com",
                                   INTERNET_DEFAULT_HTTPS_PORT, 0);

if (hConnect)
        hRequest = WinHttpOpenRequest( hConnect, L"POST", objname,
                                       NULL, NULL, 
                                       WINHTTP_DEFAULT_ACCEPT_TYPES, 
                                       WINHTTP_FLAG_SECURE);
 if (hRequest)
        bResults = WinHttpSendRequest( hRequest,
                                       WINHTTP_NO_ADDITIONAL_HEADERS,
                                       0, parameters, dwLen, 
                                       dwLen, 0);


 if (bResults)
        bResults = WinHttpReceiveResponse( hRequest, NULL);

After running the program the result shows that I have not put username and password in the username password field, but the POST data is correct, so I assume "WinHttpSendRequest" is failing to send the post data :( , also I am newbie in winhttp coding , so maybe I am punting the POST data to send in the wrong place? please help..


Thanks in advance

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.