我正在使用 gSOAP 2.8.15,并尝试按照 gsoap 文档 ( http://www.cs.fsu.edu/~engelen/soapdoc2.html#tth_sEc19.14 ) 第 19.14 节中的说明来实现 HTTP 身份验证。
唯一的区别是文档中介绍的代码是用 C 编写的,而我是用 C++ 编写的。
这是我的网络服务客户端代码
// The variable wsp is a instance of web service proxy generated by soapcpp2.
// The proxy is a sub-class of the class soap
wsp.userid = "user";
wsp.passwd = "password";
// call the function of web service
wsp.get_version(&result);
在服务器端,我使用这些代码来检查身份验证:
// The variable wss is the a instance of web service service generated by soapcpp2.
if (wss.userid == NULL || wss.passwd == NULL)
//......
问题是当我使用客户端代码调用Web服务的功能时,服务器端的userid和passwd始终为NULL。但是当我使用soapUI通过抢先授权模式传递userid和passwd来调用相同的函数时,服务器将毫无问题地获取信息。
如果有人能帮助我解决问题,我将不胜感激。感谢您的关注。
最佳答案
我使用tcpdump捕获Web服务服务器和客户端之间发送的包,发现当客户端调用Web服务的函数时没有发送http header 。于是我在gSOAP的文档中进行了一些搜索,发现了这样一句话:
A client may use the http:// prefix. When absent, no HTTP header is sent and no HTTP-based information will be communicated to the service.
它解决了我的问题...
关于c++ - gSOAP HTTP 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18352297/