webrequest ok with htttp but fails using https

  • Thread starter Thread starter taggart-chesh
  • Start date Start date
T

taggart-chesh

Guest
Hi all

need some help. The following code works fine with the http uri but when i change it to https i get a connection error

{"The underlying connection was closed: An unexpected error occurred on a send."}

what am i doing wrong?

any help apperciated.


Public Class Form1

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

Dim inputparam As String = "{""MemberId"" : ""memberid"", ""UpdateDate"": ""19/09/2019 07:48:06""}"
Dim mydata = Encoding.UTF8.GetBytes(inputparam)

Dim myUri As New Uri("https://mas-api.websites.net/api/clientservices/GetCases")

Dim result_post = SendRequest(myUri, mydata, "application/json", "POST")

TextBox1.Text = result_post


End Sub

Private Function SendRequest(uri As Uri, jsonDataBytes As Byte(), contentType As String, method As String) As String
Dim req As WebRequest = WebRequest.Create(uri)


req.ContentType = contentType
req.Method = method
req.ContentLength = jsonDataBytes.Length



Dim stream = req.GetRequestStream()
stream.Write(jsonDataBytes, 0, jsonDataBytes.Length)
stream.Close()

Dim response = req.GetResponse().GetResponseStream()

Dim reader As New StreamReader(response)
Dim res = reader.ReadToEnd()
reader.Close()
response.Close()

Return res
End Function


End Class

Continue reading...
 
Back
Top