Good morning. I need a bit of help, hoping someone out there can assist.
I need to connect to a website that requires me to login by sending POSTData with usernames and passwords, this then returns JSON data that I need to process.
I've tried WebWiewExtras, but cannot figure out how to get this done. Something else I've tried is doing the request using a httpjob and displaying the result in a webview but I cannot seem to get it.
Below is what I do in Visual Basic.
I need to connect to a website that requires me to login by sending POSTData with usernames and passwords, this then returns JSON data that I need to process.
I've tried WebWiewExtras, but cannot figure out how to get this done. Something else I've tried is doing the request using a httpjob and displaying the result in a webview but I cannot seem to get it.
Below is what I do in Visual Basic.
Login:
Dim PostString As String
PostString = "{ ""ClientType"": ""LEGEND"",""Username"": """ & username & """,""Password"": """ & password & """,""OperatorName"": """ & "JOHN" & """,""isOperatorAdmin"": " & True & ",""TillName"": """ & "POS1" & """,""PrinterWidth"": """ & 40 & """ }"
Dim urlstring As String = "http://127.0.0.1:8080/DesertView/LoginServlet"
Dim additionalHeaders As String = "Content-Type: application/json"
Dim targetFrameName As String = ""
WebBrowser1.Navigate(urlstring, targetFrameName, StringToBytes(PostString), additionalHeaders)
WebBrowser1.Refresh(WebBrowserRefreshOption.Completely)
Response:
Public Function DesertViewResponse(ByVal jsonResponse As String) As Boolean
'The response messages from DesertView will be caught here
'Responses are json Encoded.
'Deserialize json response into object (i'm using NewtonSoft but anything will work)
Dim objResponse = JsonConvert.DeserializeObject(Of Legend_VoucherResponse)(jsonResponse)
'Deserialize the Print String
Dim bytes() As Byte
Dim base64Decode As String
bytes = System.Convert.FromBase64String(objResponse.PrintString)
base64Decode = System.Text.UTF8Encoding.UTF8.GetString(bytes)
RetValue.MessageType = objResponse.MessageType
RetValue.PrintString = base64Decode
RetValue.Cost = objResponse.Cost
RetValue.HasVat = objResponse.HasVat
RetValue.Value = objResponse.Value
RetValue.VariableRate = objResponse.VariableRate
RetValue.VoucherCode = objResponse.VoucherCode
RetValue.VoucherName = objResponse.VoucherName
End Function
End Class