2015-05-16 28 views
1

我有下面的代碼發送響應,但只有前4個字節發送作爲響應。爲什麼這些行爲是這樣的?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); 
+0

只是爲了添加實現了http獲取方法這個 –

回答

3

由於respMsgchar *,它的大小相當於在你的系統,它給你的問題描述的任何其他指針似乎是4個字節(32位):

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

如果respMsg是一個字符串,那麼使用strlen(respMsg) [這是你的小例子中的情況],如果它是某種二進制數據,那麼你將需要傳遞實際大小。

+0

好這似乎克服了這個問題,但現在即時通訊從我的客戶端發送請求的響應500。儘管我的服務器的響應是200。 –

0
sizeof(respMsg) 

這是4,因爲你的指針是32位,也就是4個字節。

你想

strlen(respMsg)