I want to send data to my web server from my windows application.
Firstly i was sending data with URL parameters but due to URL lenght limit it was failing with large data. Then i tried to send data like file uploads but my data is not a file. It is very long string(about 4k chars).
So file upload tutorials on internet i replaced FileStream with my byte array but on server side $_FILES
variable is an empty array.
Here is my code.
Sub sendData(ByVal data As String)
Dim enc_data As String = EncryptRJ256(data)
Dim byteData() As Byte = Encoding.UTF8.GetBytes(enc_data)
Dim postReq As HttpWebRequest = WebRequest.Create("http://example.com")
postReq.Method = "POST"
postReq.KeepAlive = True
postReq.AllowWriteStreamBuffering = True
postReq.ContentLength = byteData.Length
Dim postreqstream As Stream = postReq.GetRequestStream()
postreqstream.Write(byteData, 0, byteData.Length)
postreqstream.Close()
Dim postresponse As HttpWebResponse
postresponse = postReq.GetResponse()
Dim postreqreader As New StreamReader(postresponse.GetResponseStream())
Dim thepage As String = postreqreader.ReadToEnd
File.WriteAllText("C:\Users\kenar\Desktopesponse.txt", thepage)
End Sub
There is nothing to show on server side. I'm using apache web server and checking $_FILES
variable on PHP script.