嘿伙计们,我正在启动一个 EPP 客户端,它只返回来自服务器的问候语,即使我尝试发送我的登录命令也是如此。
这是我的代码,它有什么问题?
using (var _tcpClient = new TcpClient(_endpoint.Host, _endpoint.Port))
{
using (var sslStream = new SslStream(_tcpClient.GetStream(), false, ValidateServerCertificate))
{
sslStream.AuthenticateAsClient(_endpoint.Host);
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(requestData);
xdoc.Save("C:/request.xml");
string data = xdoc.InnerXml;
byte[] bytedata = Encoding.UTF8.GetBytes(data);
//Get the request stream.
sslStream.Write(bytedata, 0, bytedata.Length);
// Write the data to the request stream.
sslStream.Flush();
var response = ReadMessage(sslStream);
XResponse = XDocument.Parse(response);
XResponse.Save("C:/response.xml");
}
}
return XResponse;
}
private string ReadMessage(SslStream sslStream)
{
// The first four bytes will be the the content length as a network order (big-endian) 32-bit number.
var lengthBytes = new byte[4];
sslStream.Read(lengthBytes, 0, 4);
Array.Reverse(lengthBytes);
var length = BitConverter.ToInt32(lengthBytes, 0) - 4;
// Create a byte array of the correct size for the response.
var messageBytes = new byte[length];
var returned = 0;
while (returned != length)
{
returned += sslStream.Read(messageBytes, 0, length);
}
return Encoding.UTF8.GetString(messageBytes);
}
即使我没有用 ssl 流写任何东西,它仍然会返回问候语。
如果你们能指出我正确的方向,将不胜感激。