- Edited
Hello to everybody. I'm new here and I'm new in working with http. I need to create tickets by API, so I wrote a visual basic .net to dektop application.
Unfortunately, something doesen't work correctly. I googled about my trouble but I still can't create tickets.
When I try to create a ticket i get this error: Underlined connection close. Impossible to establish a trusted relation on a SSL/TLS secure channel.
At the moment osticket is installed on my PC, so localhost is my server.
My system is windows 10 pro
Versione osTicket v1.14.2 (cba6035)
Web Server Software Apache/2.4.37 (Win32) OpenSSL/1.0.2p PHP/5.6.40
Versione MySQL 10.1.37
Versione PHP 5.6.40
visual basic 2017 with framework .net 4.5.2
The code is:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
Dim payload As New Dictionary(Of String, Object)
payload.Add("alert", True)
payload.Add("autorespond", True)
payload.Add("source", "API")
payload.Add("name", "theuser")
payload.Add("email", "theuser@zzz.xx")
payload.Add("subject", "Test API")
payload.Add("message", "data:text/html,trouble ticket")
ServicePointManager.ServerCertificateValidationCallback = AddressOf ValidateRemoteCertificate
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
Using client As WebClient = New WebClient()
client.Headers.Add("X-API-Key", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
client.Headers.Add("Expect", String.Empty)
client.Headers.Add("User-Agent", "My osTicket Client")
Dim json As String = JsonConvert.SerializeObject(payload)
client.UploadString("https://192.168.1.167/api/http.php/tickets.json", "POST", json)
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Shared Function ValidateRemoteCertificate(ByVal sender As Object, ByVal cert As X509Certificate, ByVal chain As X509Chain, ByVal [error] As SslPolicyErrors) As Boolean
If [error] = System.Net.Security.SslPolicyErrors.None Then
Return True
End If
MsgBox("X509Certificate [{0}] Policy Error: " & cert.Subject & [error].ToString())
Return False
End Function
I noticed this: if I post on HTTPS://192.168.1.167/api/http.php/tickets.json, I get the mentioned error.
If I post on HTTP://192.168.1.167/api/http.php/tickets.json, I get error 404 object not found.
Where I'm wrong?
I appreciate any help.
Many thanks