如何在请求中通过 soap 保护数据传输?

How to secure datatransfer via soap in the request?

我使用 Soap 从 Web 服务获取数据。我采用的方法是发送带有密码和用户名的 HttpWebRequest。提供者给了我 https://www.myprovider.com 之类的东西,以及他们提供的方法的名称,例如 get_data_as_bytesget_data_as_XML 等等。我现在的问题是,这个过程是否安全,因为我没有代码来解码任何在我看来通过互联网的数据未加密的内容。或者我是否必须在 SOAP 文件中设置一些内容来请求加密?

SOAP 构建如下:

Dim soapStr As String = "<?xml version=""1.0"" encoding=""utf-8""?>" & vbCr & vbLf & "                <soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""" & vbCr & vbLf & "                   xmlns:xsd=""http://www.w3.org/2001/XMLSchema""" & vbCr & vbLf & "                   xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" & vbCr & vbLf & "                  <soap:Body>" & vbCr & vbLf & "                    <{0} xmlns=""http://tempuri.org/"">" & vbCr & vbLf & "                      {1}" & vbCr & vbLf & "                    </{0}>" & vbCr & vbLf & "                  </soap:Body>" & vbCr & vbLf & "                </soap:Envelope>"

Dim req As HttpWebRequest = DirectCast(WebRequest.Create(Url), HttpWebRequest)
req.Headers.Add("SOAPAction", (Convert.ToString("""http://tempuri.org/") & methodName) + """")
req.ContentType = "text/xml;charset=""utf-8"""
req.Accept = "text/xml"
req.Method = "POST"

对于 HttpWebRequest,您可以将协议指定为 https 以使用 SSL/TLS。让你的 SOAPAction URL 成为 https://tempuri.org/ 应该做到。

PS:在 Windows 上,您可以安装 netmon or Fiddler 以查看每条消息使用的协议。