c++ 利用msxml2.dll请求WebService

#pragma  once
#include 
" stdafx.h "
#include 
" Atlbase.h "
// #import "msxml.dll"
#import  " msxml2.dll "

using   namespace  MSXML2;
int  main( int  argc,  char *  argv[])
ExpandedBlockStart.gifContractedBlock.gif
{
    printf(
"Test of XMLHTTP by masterz!\n");
    CoInitialize(NULL);
    
try
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        IXMLHTTPRequestPtr xmlrequest;
//定义http请求对象
        
//xmlrequest.CreateInstance("Msxml2.XMLHTTP");
        xmlrequest.CreateInstance(__uuidof(XMLHTTP));//创建实列
        CComVariant vFalse(FALSE);
        CComVariant vNull(NULL);
        xmlrequest
->open("POST",bstr_t("http://localhost:1135/Service1.asmx/GetName"),vFalse,vNull,vNull);//打开WEBServeice方法GetName
        xmlrequest->setRequestHeader("Content-Type:","application/x-www-form-urlencoded");//设置Http头
        _bstr_t bsdata("name=xiaowy&password=kkkk");//use your login name 传入请求参数
        xmlrequest->send(_variant_t(bsdata));//发道数据
        BSTR bstrbody;
        xmlrequest
->get_responseText(&bstrbody);//得到返回数据
        _bstr_t bstrtbody(bstrbody);
        printf(
"%s\n",(LPCTSTR)bstrtbody);
        
//MessageBox(0,(LPCTSTR)bstrtbody,"",MB_OK);
        MSXML2::IXMLDOMDocument2Ptr m_xmldoc;
        m_xmldoc.CreateInstance(__uuidof(MSXML2::DOMDocument));
        m_xmldoc
->loadXML(bstrbody);
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//*MSXML2::IXMLDOMNodeListPtr nodesPtr;
        nodesPtr = m_xmldoc->selectNodes(_bstr_t("string"));
        LONG * length;
        HRESULT r =  nodesPtr->get_length(length);
*/

        
//MSXML2::IXMLDOMNodePtr nodePtr =
        
//BSTR * str;
        
//HRESULT result = nodePtr->get_text(str);
        MSXML2::IXMLDOMNodePtr node = m_xmldoc->documentElement->firstChild;
        LPCTSTR str 
= (LPCTSTR)node->nodeName;
        LPCTSTR str2
=(LPCTSTR)m_xmldoc->documentElement->text;
        printf(
"%s",str2);
        getchar();
    }

    
catch (_com_error &e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        printf(
"Description = '%s'\n", (char*) e.Description());
    }

    CoUninitialize();
    printf(
"program end\n");
    
return 0;
}

转载于:https://www.cnblogs.com/wubiyu/archive/2008/07/22/1248291.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值