c++ - gSoap 不发送超过 4 个字节的响应

标签 c++ linux rest gsoap

我有以下用于发送响应的代码,但响应中只发送了前 4 个字节。为什么行为是这样的?

int sendRaw(struct soap *soap, const char *respMsg)
{          
        if (soap_response(&objSoap, SOAP_FILE)) /* OK HTTP response header */
        { 
                soap_end_send(&objSoap);
                return soap->error;
        }
        for(int i = 0; i < sizeof(respMsg); i++)
        {
                if(soap_send_raw(&objSoap,&respMsg[i],1))
                {
                        return soap_end_send(&objSoap);
                }    
        }
        soap_end_send(&objSoap);
        return SOAP_OK;
}

我的使命是这样的

  const char  msg = "this is a rest response";      
  return sendRaw(&objSoap,msg); 

最佳答案

由于 respMsg 是一个 char *,它的大小等于您系统中任何其他指针的大小,给定您的问题描述似乎是 4 个字节(32 位) :

    for(int i = 0; i < sizeof(respMsg); i++)

如果 respMsg 是一个字符串,那么使用 strlen(respMsg) [在你的小例子中就是这种情况],如果它是某种二进制数据,那么您需要传递实际尺寸。

关于c++ - gSoap 不发送超过 4 个字节的响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30273933/

相关文章:

c++ - 为什么不构造内部类? C++

C++ 字符数组给出奇怪的输出

c++ - 使用迭代器的 std::vector 模板构造函数是否允许转换?

python - 脚本在通过 REST 接口(interface)传递 Unicode 时遇到问题

c++ - 如果我有固定数量的相互独立的计算,多线程是否会显着提高性能?

android - 如何修复 "SDK location not found..."?

linux - grep 和 curl 命令

linux - iptables 端口转发在重启后不会持续存在

python - Google - 目录 API(管理 SDK)创建组 - 错误

post - PUT 与 POST 上传文件 - 使用 Zend Framework 构建 RESTful API