Sometimes gSOAP calls others to provide the interface, need authentication to go in.
1. First, the user name and password are required, which can be specified as follows:
struct SOAP Info_soap;
Soap_init (&INFO_SOAP);
Info_soap.userid = "Superadmin";
INFO_SOAP.PASSWD = "123456";
2. Need to download the corresponding certificate, you can download the digital certificate with Firefox, modify the name placed under the corresponding development directory for the call, and then in the program to indicate the name of the certificate, as follows:
Soap_ssl_client_context (&info_soap, 0, NULL, NULL, "/opt/create_user/sipxcert.pem", "/opt/create_user/", null);
Note: If you want to download the specified WSDL file, to copy the corresponding download link to the specified description document, replace the IP address of the corresponding server: Https://yourdomain:8443/sipxconfig/services/*service
When you open this URL, you will be prompted to issue the certificate, and then download the certificate on it.
Under Linux you can directly enter the command to download this wsdl:wget--no-check-certificate URL--http-user=superadmin--http-password=123456
Refer to the complete code below:
#include <iostream>
#include <string>
#include "Userservicesoapbinding.nsmap"
#include "SoapH.h"
int Sendwebserviceitem (
Const char* URL,
Const char* Superadminpin,
Const char* UserName
)
{
int res =-1;
struct SOAP Info_soap;
Soap_init (&INFO_SOAP);
Info_soap.userid = "Superadmin";
INFO_SOAP.PASSWD = "123456";
Info_soap.proxy_userid = "Superadmin";
INFO_SOAP.PROXY_PASSWD = "123456";
Info_soap.send_timeout = 3;
Info_soap.recv_timeout = 3;
Soap_set_mode (&info_soap, soap_c_utfstring);
#ifdef DEBUG
Soap_set_test_logfile (&info_soap, "TEST.log");
Soap_set_test_logfile (&info_soap, "RECV.log");
Soap_set_test_logfile (&info_soap, "SEND.log");
#endif
#ifdef _PROXY_IP
_soap.proxy_host = _proxy_ip;
#endif
#ifdef _proxy_port
_soap.proxy_port = _proxy_port;
#endif
Ns1__adduser Preq;
struct __ns1__adduserresponse pres;
Preq.pin = Superadminpin;
Preq.user = new Ns1__user;
if (Preq.user = NULL)
{
Std::cout << "Preq.user new memory Failed" << Std::endl;
Soap_print_fault (&info_soap, stderr);
#ifdef DEBUG
Soap_close_logfiles (&INFO_SOAP);
#endif
Soap_cleanup (&INFO_SOAP);
Soap_destroy (&INFO_SOAP);
Soap_end (&INFO_SOAP);
Soap_done (&INFO_SOAP);
return-1;
}
std::string strUserName = userName;
Preq.user->username = strUserName;
Soap_ssl_client_context (&info_soap, 0, NULL, NULL, "/opt/create_user/sipxcert.pem", "/opt/create_user/", null);
Info_soap.authrealm = Soap_authentication_digest;
res = Soap_call___ns1__adduser (&info_soap, URL, "", &preq, Pres);
if (res!= 0)
{
Std::cout << "Soap_call___ns1__adduser error:" << res << "Soap.error:" << info_soap.error <&L T Std::endl;
#ifdef DEBUG
Soap_close_logfiles (&INFO_SOAP);
#endif
Delete Preq.user;
Preq.user = NULL;
Soap_cleanup (&INFO_SOAP);
Soap_destroy (&INFO_SOAP);
Soap_end (&INFO_SOAP);
Soap_done (&INFO_SOAP);
return-1;
}
#ifdef DEBUG
Soap_close_logfiles (&INFO_SOAP);
#endif
Delete Preq.user;
Preq.user = NULL;
Soap_cleanup (&INFO_SOAP);
Soap_destroy (&INFO_SOAP);
Soap_end (&INFO_SOAP);
Soap_done (&INFO_SOAP);
return 0;
}
int main (int argc, char* argv[])
{
if (argc!= 4)
{
Std::cout << "arg error" << Std::endl;
return-1;
}
int result = Sendwebserviceitem (argv[1], argv[2], argv[3]);
If (Result!= 0)
return-1;
return 0;
}