php – 通过https执行soap请求,并使用cURL自签名证书
我正在尝试通过https对C#编写的Web服务执行soap请求.服务器使用自签名证书.
在尝试使用 我的代码: <?php header('Content-Type: text/plain; charset=utf-8'); $url = 'https://ip:8443/ServiceName'; $admin = 'login'; $password = 'haShedPassw0rdHere'; $post = '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> // Soap service params xml </soap:Body> </soap:Envelope>'; $headers = array( 'Content-type: text/xml;charset="utf-8"','Accept: text/xml','Cache-Control: no-cache','Pragma: no-cache','SOAPAction: https://ip:8443/ServiceName','Content-length: ' . strlen($post),); $curl = curl_init(); $options = array( CURLOPT_URL => $url,CURLOPT_HTTPHEADER => $headers,CURLOPT_HTTPAUTH => CURLAUTH_ANY,CURLOPT_USERPWD => $admin . ':' . $password,CURLOPT_SSL_VERIFYPEER => false,CURLOPT_SSL_VERIFYHOST => false,CURLOPT_POST => true,CURLOPT_POSTFIELDS => $post,CURLOPT_RETURNTRANSFER => true,CURLOPT_HEADER => false,CURLOPT_FOLLOWLOCATION => true,CURLOPT_ENCODING => '',CURLOPT_AUTOREFERER => true,CURLOPT_CONNECTTIMEOUT => 120,CURLOPT_TIMEOUT => 120,CURLOPT_MAXREDIRS => 10 ); curl_setopt_array($curl,$options); var_dump($response = curl_exec($curl)); ?> 响应: string(370) " <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Body> <s:Fault> <faultcode xmlns:a="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> a:InvalidSecurity </faultcode> <faultstring xml:lang="ru-RU"> Ошибка при проверке безопасности сообщения. </faultstring> </s:Fault> </s:Body> </s:Envelope>" 哪里:
意思是这样的:
我试过了什么: > POST request with a self-signed certificate 还有更多. 问题:我做错了什么? 问候. P.S.:用PHP 5.3,PHP 5.4.14,PHP 5.5.1测试.结果是一样的. UPDv1: C#Source,由服务支持团队提供: private void Button_SetData_Click(object sender,EventArgs e) { eLeed.WebServiceClient client = new eLeed.WebServiceClient(); client.ClientCredentials.UserName.UserName = "login"; client.ClientCredentials.UserName.Password = "haShedPassw0rdHere"; Stream input = null; input = GetQuery("ServiceMethod",TextBox_Command.Text); XmlDocument response = new XmlDocument(); response.PreserveWhitespace = true; response.Load(client.SetDataContractor(input)); ExeResponse(response); input.Close(); client.Close(); } 好吧,这个按钮实际上正在工作.但是如何用cURL在php中执行类似的操作呢?特别是,如何通过这两行: client.ClientCredentials.UserName.UserName = "login"; client.ClientCredentials.UserName.Password = "haShedPassw0rdHere"; 因此,它不应该返回“无效凭据”之类的消息吗? 解决方法
错误似乎不在客户端,而是在服务器端.服务器说某些安全检查失败了.如果这是一个客户端错误,你只会得到cURL的错误.你得到一个XML答案.
你应该看一下服务器端. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |