运行使用gSOAP创建的Web服务客户端时出现SSL错误

时间:2015-03-01 13:27:31

标签: c++ web-services gsoap

我已经使用C ++和gSOAP编写了一个专门用于Web服务的客户端。目前,此客户端应调用SendSMS程序并将单个短信文本消息发送到指定的号码以代替' TO' (请见下面的鳕鱼)。该程序运行顺利,但没有传递短信文本消息。经过调查我发现了这条线

int message_status_code=service.SendSMS("https://www.experttexting.com/exptapi/exptsms.asmx","SendSMS",request_packet,request_packet_response);

给出错误代码,其值等于SOAP_SSL_ERROR。

为了解决这个问题,我在使用g ++进行编译时使用了-DWITH_OPENSSL标志,但无济于事。

请帮我调试这个问题。

#include "soapH.h"
#include "ExptTextingAPISoap.nsmap"
#include "soapExptTextingAPISoapProxy.h"

int main(){
   struct soap soap;
   soap_init(&soap);
   string UserID="MY USER Id";
   string PWD="MY PASSWORD";
   string APIKEY="MY API KEY";
   string FROM="FROM";
   string TO="RECEIVER";
   string MSG="MY MESSAGE";
   _ns1__SendSMS* request_packet=soap_new_set__ns1__SendSMS(&soap,&UserID,&PWD,&APIKEY,&FROM,&TO,&MSG);
   _ns1__SendSMSResponse* request_packet_response=soap_new__ns1__SendSMSResponse(&soap);
   ExptTextingAPISoapProxy service(soap);
   int message_status_code=service.SendSMS("https://www.experttexting.com/exptapi/exptsms.asmx","SendSMS",request_packet,request_packet_response);
   service.destroy();
   return 0;
}

1 个答案:

答案 0 :(得分:0)

您需要在进行服务调用之前提供ssl上下文。如果服务器不需要客户端身份验证,您可以使用以下代码,否则您需要提供客户端证书和密钥。

if (soap_ssl_client_context(&soap,
    /* SOAP_SSL_NO_AUTHENTICATION, */ /* for encryption w/o authentication */
    /* SOAP_SSL_DEFAULT | SOAP_SSL_SKIP_HOST_CHECK, */  /* if we don't want the host name checks since these will change from machine to machine */
    SOAP_SSL_DEFAULT,   /* use SOAP_SSL_DEFAULT in production code */
    NULL,       /* keyfile (cert+key): required only when client must authenticate to server (see SSL docs to create this file) */
    NULL,       /* password to read the keyfile */
    "cacert.pem",   /* optional cacert file to store trusted certificates, use cacerts.pem for all public certificates issued by common CAs */
    NULL,       /* optional capath to directory with trusted certificates */
    NULL        /* if randfile!=NULL: use a file with random data to seed randomness */ 
  ))
  { soap_print_fault(&soap, stderr);
    exit(1);
  }