Connecting to accounting software's API

Hi All

I started working on the API connection using Xojo.Net.HTTPSocket to connect with Saasu accounting software & have run into a problem.

Using this code…
// Self is the Xojo.Net.HTTPSocket

Self.ClearRequestHeaders

Dim requestContent As Text = Session.spsAPIRequestContent.ToText
If Not requestContent.Empty Then
Dim data As Xojo.Core.MemoryBlock
data = Xojo.Core.TextEncoding.UTF8.ConvertTextToData(requestContent)
Self.SetRequestContent(data, “application/json”)
End If

Self.Send(“POST”, Session.spsAPIRequestURL.ToText)

I am getting back a response & access token as I would expect. However, in the PageReceived event, after processing the access token, I use this code…

dim ptContent As String = kGetContacts
ptContent = ptContent.Replace("^1", mpsAccessToken)

Dim requestContent As Text = ptContent.ToText
If Not requestContent.Empty Then
Dim data As Xojo.Core.MemoryBlock
data = Xojo.Core.TextEncoding.UTF8.ConvertTextToData(requestContent)
Self.SetRequestContent(data, “application/json”)
End If

Self.Send(“GET”, Session.spsAPIRequestContactsURL.ToText)

which errors with a “ A request is already in progress.”. I moved that code into a timer on the page & it runs, but I get an "The network connection was lost.” error & no return data.

This problem is the same on both a web & desktop app.

Am I doing something wrong, or is there bug in Xojo.Net.HTTPSocket?

Regards

Chris Percival

@Chris Percival: I think the problem is that you’re trying to reuse the socket from within its PageReceived method, and as a result, the initial HTTP request is still active.

Here’s info that might help you to work around this: https://forum.xojo.com/28387-reusing-xojo-net-httpsocket/0

As an alternative you can also try our CURL Plugin.
Can work synchronously or asynchronously.

if this is on a Mac, then use PAW to test the service and it has an add-in to generate the XOJO code.

the MBS curl plugin works really well too.