Android Question Help for httputils2, json and connection for api over http.


Licensed User
Longtime User
I'm really struggling with trying to get this to work. No matter what I try I get errors and fail. I'm wondering if i can get an assist. I have read and tried httputils2 but the connection fails or errors. firewall is down and it works successfully with my code, so i know it's my approach.
What am i missing? Not SSL btw.

Working code:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        ' Dim data1 = Encoding.UTF8.GetBytes("{'command': 'summary'}")
    End Sub

    Private Sub sendCommand(ByVal command As String)
            Dim clientSocket As New System.Net.Sockets.TcpClient()
            clientSocket.Connect("", 4028)
            Dim serverStream As NetworkStream = clientSocket.GetStream()
            Dim outStream As Byte() = System.Text.Encoding.ASCII.GetBytes(command)
            serverStream.Write(outStream, 0, outStream.Length)

            Dim inStream As Byte() = New Byte(65536) {}
            serverStream.Read(inStream, 0, CInt(clientSocket.ReceiveBufferSize))
            Dim returnData As String = System.Text.Encoding.ASCII.GetString(inStream)
            '  MsgBox(returnData)
            TextBox1.Text = (returnData)
            '  Debug.Print(returnData)
        Catch exc As Exception
        End Try
    End Sub

This is just one of my attempts and the error (Error: org.apache.http.client.ClientProtocolException)
I am not sure if I am just approaching this completely wrong.

    Sub Senddata   
  Dim job2 As HttpJob 
    Dim objMap As Map: objMap.Initialize
    'Send a POST request
            job2.Initialize("Job2", Me)

            Dim objJSon As JSONGenerator: objJSon.Initialize(objMap)
            job2.PostString("HTTP://", objJSon.ToPrettyString(2))
    End Sub

At this point I've been trying for a few days and I got nowhere.
Any help or code hints would be greatly appreciated.



Licensed User
Longtime User
job2.PostString does send a POST-request to the server.
What serversoftware is on the other side which recieves the data?

Is the destination able to handle html-form-data posted by GET or POST?
Upvote 0


Licensed User
Longtime User
This is a statement from the docs.

it will listen on a
simple TCP/IP socket for single string API requests from the same machine
running cgminer and reply with a string and then close the socket each time
If you add the "--api-network" option, it will accept API requests from any
network attached computer."

It's an application and I'm pretty sure its custom and not really a webserver.
I did try other ways e.g. download, download2 as outlined in some of the samples.

I just wanted to post at least one of my failures as a sample, but I'm open to any possibilities to connect.

In the .net code i posted, it's just hitting a socket not really html.
Again, I'm probably wayoff with my b4a approach, but I don't know what i don't know.

Upvote 0