Hi!
I'm trying to send data from a mobile application written in Java ME, to an ASP.NET website connected to an SQL server. I tried to open an httpconnection output stream in the Java ME application, and send the data in a POST to the website. The problem is I don't know how to accept data on the website. I found code online that I tried to modify to suit my application, but I feel I'm waaaay off. Could anyone give me some pointers on how to go about this?

Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click

        Dim str As Stream
        Dim strLen As Integer
        Dim strRead As Integer


        'Request input stream from the poster
        str = Request.InputStream


        'Get the length of incoming string
        While (strLen = 0)
            strLen = str.Length
        End While

        'make a Byte array the size of the stream
        Dim strArr(strLen) As Byte


        'read the stream into the array
        strRead = str.Read(strArr, 0, strLen)

        Label1.Text = strArr.ToString()


    End Sub
Member Avatar for stbuchok

Why not save the data in the database and display that data on the ASP.Net page? You can then have an AJAX web service that loops to see if there is new data in the database to display.

You mean send the data directly from the mobile phone to the SQL server? I didn't look into that because in other forums I saw people asking about that, and everyone would reply, you'll need to add a webpage with that. Is it doable?

Member Avatar for stbuchok

Just create a web service. the web service will be able to be used by any language that supports web services and any device that has an internet connection. You will be able to send data through to the database and use another web service to grab the data.

Ok I'm sorry, but I'm new to this and I'm really confused. I've already written the Java ME application that sends data using an HTTP post, and I've already made the website using ASP.NET. So I'd prefer not to get into web services. Forget the SQL server, where in my ASP.NET application should I accept the data coming from the mobile phone? It doesn't really make sense in the page_load event? Because that doesn't seem right to me.

In case someone ever has the same problem, turns out the above code is pretty much right. I added these lines of code to make it work better:

' the stream will be ASCII encoded'
         Dim ascii As ASCIIEncoding = New ASCIIEncoding

        'Get ASCII into reg. string here'
         strmContent = ascii.GetString(strArr)
         Label1.Text = strArr.ToString()

        'write the received data to a text file'
        Dim FILE_NAME As String = "C:\\NP\\received.txt"
        Dim objWriter As New System.IO.StreamWriter(FILE_NAME, True)
        objWriter.WriteLine(strmContent)
        objWriter.WriteLine()
        objWriter.Close()

Most of the code I used came from this forum discussion, if you'd like to look at it: http://bytes.com/topic/asp-net/answers/327711-receive-https-post
And the code should be placed in the ASP.NET page-load event.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.