Note that there are some explanatory texts on larger screens.

plurals
  1. POPerform soap request via https with self-signed certificate by cURL
    primarykey
    data
    text
    <p>I'm trying to perform soap request to web-service written on C# via https. Server uses self-signed certificate.</p> <p>After many failed attempts with usage of <a href="http://php.net/SoapClient" rel="nofollow noreferrer"><code>SoapClient</code></a> I decided to use pure <a href="http://php.net/curl" rel="nofollow noreferrer"><code>cURL</code></a> to perfrom request.</p> <p>My code:</p> <pre><code>&lt;?php header('Content-Type: text/plain; charset=utf-8'); $url = 'https://ip:8443/ServiceName'; $admin = 'login'; $password = 'haShedPassw0rdHere'; $post = '&lt;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/"&gt; &lt;soap:Body&gt; // Soap service params xml &lt;/soap:Body&gt; &lt;/soap:Envelope&gt;'; $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 =&gt; $url, CURLOPT_HTTPHEADER =&gt; $headers, CURLOPT_HTTPAUTH =&gt; CURLAUTH_ANY, CURLOPT_USERPWD =&gt; $admin . ':' . $password, CURLOPT_SSL_VERIFYPEER =&gt; false, CURLOPT_SSL_VERIFYHOST =&gt; false, CURLOPT_POST =&gt; true, CURLOPT_POSTFIELDS =&gt; $post, CURLOPT_RETURNTRANSFER =&gt; true, CURLOPT_HEADER =&gt; false, CURLOPT_FOLLOWLOCATION =&gt; true, CURLOPT_ENCODING =&gt; '', CURLOPT_AUTOREFERER =&gt; true, CURLOPT_CONNECTTIMEOUT =&gt; 120, CURLOPT_TIMEOUT =&gt; 120, CURLOPT_MAXREDIRS =&gt; 10 ); curl_setopt_array($curl, $options); var_dump($response = curl_exec($curl)); ?&gt; </code></pre> <p>Response:</p> <pre><code>string(370) " &lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt; &lt;s:Body&gt; &lt;s:Fault&gt; &lt;faultcode xmlns:a="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"&gt; a:InvalidSecurity &lt;/faultcode&gt; &lt;faultstring xml:lang="ru-RU"&gt; Ошибка при проверке безопасности сообщения. &lt;/faultstring&gt; &lt;/s:Fault&gt; &lt;/s:Body&gt; &lt;/s:Envelope&gt;" </code></pre> <p>Where:</p> <blockquote> <p>Ошибка при проверке безопасности сообщения.</p> </blockquote> <p>Means something like:</p> <blockquote> <p>Communication security check error.</p> </blockquote> <p>What have I tried:</p> <ol> <li><a href="https://stackoverflow.com/questions/13690173/post-request-with-a-self-signed-certificate">POST request with a self-signed certificate</a></li> <li><a href="https://stackoverflow.com/questions/6652227/how-to-consume-a-wcf-web-service-that-uses-custom-username-validation-with-a-php">How to consume a WCF Web Service that uses custom username validation with a PHP page?</a></li> <li><a href="https://stackoverflow.com/questions/9909232/php-soapclient-stream-context-option">Php SoapClient stream_context option</a></li> <li><a href="https://stackoverflow.com/questions/3934639/soap-authentication-with-php">SOAP authentication with PHP</a></li> <li><a href="https://stackoverflow.com/questions/3006977/how-can-i-send-soap-xml-via-curl-and-php">How can I send SOAP XML via Curl and PHP?</a></li> </ol> <p>And more of them.</p> <p><strong>Question:</strong> What am I doing wrong?</p> <p>Regards.</p> <p><strong>P.S.:</strong> Tested with <code>PHP 5.3</code>, <code>PHP 5.4.14</code>, <code>PHP 5.5.1</code>. Results are same.</p> <hr> <p><strong>UPDv1:</strong></p> <p>C# Source, provided by service support team:</p> <pre><code>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(); } </code></pre> <p>Well, this button is actually working. But how perform something like that in php with cURL ? Especially, how to pass those two lines:</p> <pre><code>client.ClientCredentials.UserName.UserName = "login"; client.ClientCredentials.UserName.Password = "haShedPassw0rdHere"; </code></pre> <p>Therefore, shouldn't it return message like "invalid credentials" or something?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload