簡體   English   中英

通過https執行soap請求,並使用cURL自簽名證書

[英]Perform soap request via https with self-signed certificate by cURL

我正在嘗試通過https對C#編寫的Web服務執行soap請求。 服務器使用自簽名證書。

在嘗試使用SoapClient失敗后,我決定使用純cURL來執行請求。

我的代碼:

<?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>"

哪里:

Ошибкаприпроверкебезопасностисообщения。

意思是這樣的:

通信安全檢查錯誤。

我試過了什么:

  1. 帶有自簽名證書的POST請求
  2. 如何使用在PHP頁面上使用自定義用戶名驗證的WCF Web服務?
  3. Php SoapClient stream_context選項
  4. 使用PHP進行SOAP身份驗證
  5. 如何通過Curl和PHP發送SOAP XML?

還有更多。

問題:我做錯了什么?

問候。

PS:使用PHP 5.3PHP 5.4.14PHP 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答案。

你應該看一下服務器端。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM