Advise on httpClient
Posted
#1
(In Topic #879)
Enthusiast

"Invalid authorization credentials provided"
Below is my code i am currently using
Code
Dim hClient as HttpClient
Dim sBuffer as String
hClient = New HttpClient as "hClient"
With hClient
.URL = Global.PS_URL &"/terminals/" & global.TerminalNumber
.Auth = 1
.User = Base64$(global.PS_User)
.Password = Base64$()Gl;obal.PS_Pass)
'.Headers.Add("Software-House-ID :SD45T92")
'.Headers.Add("Installer-Id : SD45T92")
.Sync = False
.Timeout = 60
.Get
End With
the global.PS_URL and global.TerminalNumber are populated when the application starts and it creates the correct URL needed
Can someone tell me how I can send the user name and Password to the cloud server, Also as you can see the 2 headers.add are
commented out as when I try to include them I get a error (do I need to you a different method of sending that information to
the cloud server I am talking to.
Any help is most appreciated as once I get this working I should be able to work out how to read the Json data that is returned
(if anyone has any examples of this they would be very much appreciated)
Andy
Posted
Guru

If so, try something like this: -
This will get the File.json from the root directory of MySite.com and save it in your Home folder as File.json
Posted
Enthusiast

In Windows i can get the terminal status via the following code
Code
Try
Dim Request As HttpWebRequest = HttpWebRequest.Create(PS_URL & "/terminals/" & TerminalIDNumber)
Dim credentials As String = Convert.ToBase64String(Encoding.ASCII.GetBytes(PS_USER & ":" & PS_PASS))
txtResults.Text = vbNullString
With Request
.Proxy = Nothing
.Headers(HttpRequestHeader.Authorization) = String.Format("Basic \{0}", credentials)
.Accept = "application/connect.v2+json"
.Headers.Add("Software-House-Id: SD459T92") ' algPoS ID Number
.Headers.Add("Installer-Id:" & InstallerID)
.UserAgent = PS_USER
End With
Dim response As HttpWebResponse = Request.GetResponse()
Dim dataStream As Stream = response.GetResponseStream
Dim reader As New StreamReader(dataStream)
Dim responseFromServer As String = reader.ReadToEnd()
txtResults.Text = responseFromServer
If responseFromServer = "0" Then
MsgBox("Retreal of Status Failed")
Else
Dim json As String = responseFromServer
Dim ser As JObject = JObject.Parse(json)
Dim data As List(Of JToken) = ser.Children().ToList
For Each item As JProperty In data
item.CreateReader()
Select Case item.Name
Case "status"
Select Case item.Value
Case "AVAILABLE"
GetStatus = 1
If DontSendDataToPoS = 0 Then SendToPoSterminal("TerminalOnLine|")
Me.ListBox1.Items.Clear
addtoStatusList("Terminal Ready")
Case "BUSY"
If DontSendDataToPoS = 0 Then SendToPoSterminal("TerminalBusy|")
addtoStatusList("Terminal busy please wait 10 seconds and try again")
Case "Offline", "OFFLINE", "offline"
If DontSendDataToPoS = 0 Then SendToPoSterminal("offline|")
addtoStatusList("Terminal OFFLINE NO Card processing Possible - Please check with Payment Sense")
End Select
End Select
Next
End If
Catch ex As Exception
addtoStatusList(ex.ToString)
If DebugActive = "Yes" Then AddToDebugList(ex.ToString)
If DontSendDataToPoS = 0 Then SendToPoSterminal("ProcessingError")
FromPoSTCP.Stop()
FromPoSTCP.Start()
End Try
The above works perfectly so I need to work out how to make it work in Gambas (once i have this I can can crack on with the rest of the module)
1 guest and 0 members have just viewed this.



