How to send/receive a picture file to server using Base64?
i am doing a project tat required me to send/receive a picture file to the server (tomcat) and below is my codes. This code can allow me to send the picture thru the xml and create another xml package. But when i tried sending to my fren's server, i can't send thru, please help me with it...!!
thanks!!
=============================================
Imports System.Net.Sockets
Imports System.IO
Imports System.Xml.XmlDocument
'Imports MSWinsockLib
Imports System.Net.SocketAddress
'Imports System.Text.Encoding
Imports System.Xml.XmlReader
Imports System.Xml
Public Class Form1
Inherits System.Windows.Forms.Form
' Dim WithEvents mywinsock As New Winsock
'Dim sc As TcpClient
Dim tcpClient As New System.Net.Sockets.TcpClient
'Dim f1 As New SocketConnection
'Dim tl As TcpListener
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim networkStream As NetworkStream = tcpClient.GetStream()
Dim sendBytes As Byte() = System.Text.Encoding.ASCII.GetBytes("hello")
Dim Doc As New XmlDocument
Doc.Load("orders.xml")
Dim LogoNode As XmlNode
LogoNode = Doc.CreateElement("Logo")
Dim fs As New FileStream("logo.bmp", FileMode.Open)
Dim LogoBytes(Convert.ToInt32(fs.Length)) As Byte
fs.Read(LogoBytes, 0, LogoBytes.Length)
Dim EncodedText As String = Convert.ToBase64String(LogoBytes)
LogoNode.AppendChild(Doc.CreateTextNode(EncodedText))
Doc.DocumentElement.ChildNodes(0).AppendChild(LogoNode)
Doc.Save("orders_pic.xml")
Console.WriteLine("File Successfully 'orders_pic.xml' written.")
Console.ReadLine()
Dim myStr As String = "logo.bmp"
End Sub
Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'ock.RemoteHost = TextBox1.Text
'mywinsock.RemotePort = 6969]
'mywinsock.RemoteHost() = "152.226.131.226"
'mywinsock.RemotePort = 6969
'mywinsock.Connect()
'Dim ie As New Net.IPEndPoint(Net.IPAddress.Parse("152.226.131.226"), 6969)
'sc = New TcpClient("152.226.131.226", 6970)
tcpClient.Connect("152.226.136.173", 6969)
' Dim Doc As New XmlDocument
'Doc.Load("orders.xml")
'MonthCalendar1.MinDate = DateTime.Today
'MonthCalendar1.MaxDate = Now.AddDays(3)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'Dim b As New IO.StreamReader(sc.GetStream)
Dim networkStream As NetworkStream = tcpClient.GetStream()
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
' networkStream.Write(
'System.Text.Encoding.ASCII.GetBytes("abc")
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
Dim returndata As String = System.Text.Encoding.ASCII.GetString(bytes)
TextBox2.Text = returndata
End Sub
Private Sub MonthCalendar1_DateChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateChanged
MsgBox("allan here")
End Sub
End Class
Best Regards
Allan