我試圖通過https對C#上編寫的web服務執行soap請求。服務器使用自簽名證書。通過https與自簽名證書通過cURL執行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>"
其中:
Ошибкаприпроверкебезопасностисообщения。
意思是這樣的:
通信安全檢查錯誤。
有什麼我想:
- POST request with a self-signed certificate
- How to consume a WCF Web Service that uses custom username validation with a PHP page?
- Php SoapClient stream_context option
- SOAP authentication with PHP
- How can I send SOAP XML via Curl and PHP?
其中更多。
問題:我做錯了什麼?
問候。
P.S:測試與PHP 5.3
,PHP 5.4.14
,PHP 5.5.1
。結果是一樣的。
UPDv1:
C#源代碼,以服務支持團隊提供:
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";
因此,它不應該像返回「無效憑證」什麼消息?
你能翻譯俄語錯誤信息 – DevZer0
@ DevZer0對不起。剛注意到。 – BlitZ
soap api是否規定了某種形式的安全機制,比如某種形式的標題中的主體哈希?如果您熟悉亞馬遜的'MWS'則需要使用私鑰創建簽名,使用身體的所有有效載荷作爲頭部的一部分傳入 – DevZer0