Im try to read an xml file and send to server with sslStream. Before send to server i must make Login and after succesfull authorization i must send the fileData. To fileSize is about 300kb. I can make sycessfull the login, but the problem is that server seems to not receive the data that i send. here is the code method1: I suceesfull make login(i receive ok but it seems that i can't send the contents of xml file)
TcpClient sendClient = new TcpClient(serverName, port);
SslStream sendStream = new SslStream(sendClient.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
sendStream.AuthenticateAsClient(serverName, null, SslProtocols.Ssl2, true);
sendStream.Write(Encoding.UTF8.GetBytes("Login\r\n" + username + "\r\n" + password + "\r\n"));
sendStream.Flush();
int bytes = -1;
byte[] buffer = new byte[2048];
bytes = sendStream.Read(buffer, 0, buffer.Length);
string response = Encoding.UTF8.GetString(buffer, 0, bytes);
if (response.Trim() == "OK")
{
MessageBox.Show("Connected");
byte[] b1 = File.ReadAllBytes(filePath);
sendStream.Write(Encoding.UTF8.GetBytes("Send\r\n"));
sendStream.Write(Encoding.UTF8.GetBytes(fileName+"\r\n"));
sendStream.Write(b1, 0, b1.Length);
sendStream.Flush();
sendStream.Write(Encoding.UTF8.GetBytes("Quit\r\n"));
sendStream.Flush();
sendClient.Close();
}
and here is a second method with streamWriter
TcpClient sendClient = new TcpClient(serverName, port);
SslStream sendStream = new SslStream(sendClient.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
sendStream.AuthenticateAsClient(serverName, null, SslProtocols.Ssl2, true);
StreamWriter writer = new StreamWriter(sendStream);
writer.WriteLine("Login");
writer.WriteLine(username);
writer.WriteLine(password);
writer.Flush();
StreamReader reader = new StreamReader(sendStream);
string response = reader.ReadLine();
if (response.Trim() == "OK")
{
MessageBox.Show("succesfull connect");
string allText = File.ReadAllText(filePath,Encoding.Default);
writer.WriteLine("Send");
writer.WriteLine(fileName);
writer.WriteLine(allText);
sendClient.Close();
}