I am using following code to send the data ...
int _tmain(int argc, _TCHAR* argv[])
{
hEvent = CreateEvent(NULL, false, false, NULL);
AsyncWinHttp http;
http.Initialize(WinHttp_CallBack);
http.SetTimeout(3 * 60 * 1000);
strData = "Data to be send";
LPVOID lpBuffer = (LPVOID)strData.c_str();
http.SendRequest(L"http://localhost:1429/AIS-Abstractor/DataFromAgent/AgentInstallationDetails.aspx",&lpBuffer,"POST");
WaitForSingleObject(hEvent, INFINITE);
CloseHandle(hEvent);
}
bool AsyncWinHttp::SendRequest(LPWSTR szURL,LPVOID lpBuffer,char strRequest[4])
{
WCHAR szHost[256];
DWORD dwOpenRequestFlag = 0;
URL_COMPONENTS urlComp;
bool fRet = false;
ZeroMemory(&urlComp, sizeof(urlComp));
urlComp.dwStructSize = sizeof(urlComp);
urlComp.lpszHostName = szHost;
urlComp.dwHostNameLength = sizeof(szHost) / sizeof(szHost[0]);
urlComp.dwUrlPathLength = -1;
urlComp.dwSchemeLength = -1;
swprintf_s( memo_, L"WinHttpCrackURL");
if (!WinHttpCrackUrl(szURL, 0, 0, &urlComp))
{
goto cleanup;
}
swprintf_s( memo_, L"WinHttpConnect");
connect_ = WinHttpConnect(session_, szHost,
urlComp.nPort, 0);
if (NULL == connect_)
{
goto cleanup;
}
dwOpenRequestFlag = (INTERNET_SCHEME_HTTPS == urlComp.nScheme) ? WINHTTP_FLAG_SECURE : 0;
swprintf_s( memo_, L"WinHttpOpenRequest");
if(strcmp(strRequest, "GET")== 0)
{
request_ = WinHttpOpenRequest(connect_,
L"GET", urlComp.lpszUrlPath,
NULL, WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
dwOpenRequestFlag);
}
else
{
request_ = WinHttpOpenRequest(connect_,
L"POST", urlComp.lpszUrlPath,
NULL, WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
dwOpenRequestFlag);
}
if (request_ == 0)
{
goto cleanup;
}
swprintf_s( memo_, L"WinHttpSetStatusCallback");
WINHTTP_STATUS_CALLBACK pCallback = WinHttpSetStatusCallback(request_,
(WINHTTP_STATUS_CALLBACK)AsyncCallback,
WINHTTP_CALLBACK_FLAG_ALL_COMPLETIONS |
WINHTTP_CALLBACK_FLAG_REDIRECT,
NULL);
if (pCallback != NULL)
{
goto cleanup;
}
swprintf_s( memo_, L"WinHttpSendRequest");
if(strcmp(strRequest, "GET")== 0)
{
if (!WinHttpSendRequest(request_,
WINHTTP_NO_ADDITIONAL_HEADERS, 0,
WINHTTP_NO_REQUEST_DATA, 0, 0,
(DWORD_PTR)this))
{
goto cleanup;
}
}
else
{
if (!WinHttpSendRequest(request_,
_T("Content-Type: application/x-www-form-urlencoded"),
-1L,lpBuffer,100,100,(DWORD_PTR)this))
{
goto cleanup;
}
}
fRet = true;
cleanup:
if (fRet == false)
{
WCHAR szError[256];
swprintf_s(szError, L"%s failed with error %d", memo_, GetLastError());
status.set(ASYNC_WINHTTP_ERROR, szError);
Cleanup();
}
return fRet;
}