#include  < string >
#include 
< iostream >
#import 
< msxml4.dll >

void  SendData(std::wstring url, std::wstring username, std::wstring password)
{

    HRESULT hr;
    MSXML2::IXMLHTTPRequestPtr pIXMLHTTPRequest;
    MSXML2::IXMLDOMDocumentPtr pXMLDoc;
    std::wstring wvarQuery(L
" username= " );
    wvarQuery.append(username);
    wvarQuery.append(L
" &password= " );
    wvarQuery.append(password);
    _variant_t vartQueryFields(wvarQuery.c_str());

    
try
    {
        CoInitialize(NULL);
        hr
= pIXMLHTTPRequest.CreateInstance(__uuidof(MSXML2::XMLHTTP));
        SUCCEEDED(hr) 
?   0  :  throw  hr;

        hr
= pIXMLHTTPRequest -> open( " POST " , url.c_str(), 
            
false );
        SUCCEEDED(hr) 
?   0  :  throw  hr;
        
// 如果要向服务器post数据,这个地方一定要设置为application/x-www-form-urlencoded
        pIXMLHTTPRequest -> setRequestHeader( " Content-Type " " application/x-www-form-urlencoded " );

        hr 
=  pIXMLHTTPRequest -> send( vartQueryFields );
        SUCCEEDED(hr) 
?   0  :  throw  hr;
        
// 拿到返回来的xml数据
        pXMLDoc = pIXMLHTTPRequest -> responseXML;
        
// 后面就是对拿回来的xml数据进行解析,主要是dom方法
    }
    
catch ()
    {
        
if (pIXMLHTTPRequest)
            pIXMLHTTPRequest.Release();
        
if (pXMLDoc)
            pXMLDoc.Release();
        CoUninitialize();
    }
}


int  main()
{
    SendData(L
" http://localhost/login.php " , L " kenwell " , L " kenwell " );
}