gsoap报文打印

本文介绍了在gSOAP库中,如何在客户端和服务器端处理XML报文。在客户端,详细展示了如何获取并打印请求和响应报文的XML内容。在服务器端,讲解了接收客户端请求报文并记录,以及发送应答报文的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

作为客户端的时候
soap_begin_recv
    //发送完请求报文 获取请求报文信息
    g_str_reqXml.clear();
    std::string strBuf;
    std::string::size_type pos1= std::string::npos;
    std::string::size_type pos2 = std::string::npos;
    strBuf = soap->buf;
    pos1 = strBuf.find("<?xml",0);
    pos2 = strBuf.find("</SOAP-ENV:Envelope>",0);
    if(pos1!=std::string::npos && pos2!=std::string::npos)
    {
        g_str_reqXml = strBuf.substr(pos1,pos2-pos1+20);
    }

soap_body_end_in
    //接收完应答报文 获取应答报文信息
    g_str_resXml.clear();
    std::string strBuf;
    std::string::size_type pos1= std::string::npos;
    std::string::size_type pos2 = std::string::npos;
    pos1= std::string::npos;
    pos2 = std::string::npos;
    soap->buf[SOAP_BUFLEN-1] = '\0';
    strBuf = soap->buf;
    pos1 = strBuf.find("<?xml",0);
    pos2 = strBuf.find("</soapenv:Envelope>",0);
    if(pos1!=std::string::npos && pos2!=std::string::npos)
    {
        g_str_resXml = strBuf.substr(pos1,pos2-pos1+19);
    }

作为服务端的时候
soap_recv_raw
    //接收完客户端的请求报文 获取请求报文信息
    DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes from socket=%d/fd=%d\n", (unsigned int)ret, soap->socket, soap->recvfd));
    DBGMSG(RECV, soap->buf, ret);

    //请求报文
    std::string req_data;
    req_data.assign(soap->buf, ret);
    g_pLog->WriteLog(req_data.c_str(), LOG_INFO);

soap_flush_raw
    DBGMSG(SENT, s, n);
    DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Send %u bytes to socket=%d/fd=%d\n", (unsigned int)n, soap->socket, soap->sendfd));

    //应答报文
    std::string res_data;
    res_data.assign(s, n);
    g_pLog->WriteLog(res_data.c_str(), LOG_INFO);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值