I have zero experience of sending POST requests to a REST api so first I tried sending the whole xml/text payload including the headers and body as a string by reading it from the File.DirAssets folder (very optimistic I know!), when I did this the remote server responds with "Unauthorized" error.
The Basic login and password string (format loginassword in base64) is correct as I converted it myself using B4J code and when it didn't work I then used Fiddler to capture the real packet sent from the browser and it matches my own string so the login credentials are correct. I am using the jOKHttpUtils2 library.
This is the full REST payload that I captured and this works when sent from a web based test utility:
But I cannot figure out how to emulate the same thing using B4J.
I then used the following simple B4J code to send the header login and password separately and just the body packet as "requestREST.xml":
Instead of an "Unauthorized" error this time I get the error: "Internal Server Error"
I know I must be making some very simple mistake somewhere, any advice would be really appreciated?
The Basic login and password string (format loginassword in base64) is correct as I converted it myself using B4J code and when it didn't work I then used Fiddler to capture the real packet sent from the browser and it matches my own string so the login credentials are correct. I am using the jOKHttpUtils2 library.
This is the full REST payload that I captured and this works when sent from a web based test utility:
B4X:
POST https://ifc.int.hot-sos.net/api/service.svc/rest/serviceorder HTTP/1.1
Host: ifc.int.hot-sos.net
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0
Accept: text/plain, */*; q=0.01
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: https://ifc.int.hot-sos.net/api/pages/test/
Content-Type: text/xml; charset=UTF-8
Authorization: Basic RWxlY29uaW50X1N5c3RlbTp0ZXN0aW5nMTIz
X-Requested-With: XMLHttpRequest
Content-Length: 329
Connection: keep-alive
<ServiceOrder xmlns="urn:serviceorder.api.m-tech.com" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Issue xmlns:a="urn:issue.api.m-tech.com">
<ID xmlns="urn:api.m-tech.com">10744</ID>
</Issue>
<Location xmlns:a="urn:room.api.m-tech.com">
<ID xmlns="urn:api.m-tech.com">600</ID>
</Location>
</ServiceOrder>
But I cannot figure out how to emulate the same thing using B4J.
I then used the following simple B4J code to send the header login and password separately and just the body packet as "requestREST.xml":
B4X:
Sub REST_Job
Dim j As HttpJob
j.Initialize("j", Me)
Dim msg As String
msg = File.ReadString(File.DirAssets, "requestREST.xml")
Log(msg)
j.Username="xxxxxxxxxxx"
j.Password="xxxxxxxxxxx"
j.PostString("https://ifc.int.hot-sos.net/api/service.svc/rest/serviceorder", msg)
End Sub
Sub JobDone (Job As HttpJob)
Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
If Job.Success = True Then
Log(Job.GetString)
Else
Log("Error: " & Job.ErrorMessage)
End If
Job.Release
End Sub
Instead of an "Unauthorized" error this time I get the error: "Internal Server Error"
I know I must be making some very simple mistake somewhere, any advice would be really appreciated?