-
Apr 21st, 2018, 11:11 AM
#1
Thread Starter
New Member
send https with Httpwebrequest
Dear Sir;
I have a web-service that communicates with my Desktop application. Usually I used http in the webrequest, but now I want to modify my code to use https. I accessed the links from web browser normally; but I can not access the same link from my desktop application. Below is the code that I use
///////////////////////////////////////////////////
Public Function Json_Connection(url As String, content As String, ByRef statusCode As HttpStatusCode) As Byte()
dataStream = Nothing
responseFromServer = Nothing
Try
request = HttpWebRequest.Create("https://www.xxxxxxxxx.net/BackEnd/" & url)
request.ProtocolVersion = New System.Version(1, 0)
request.Timeout = 120000
request.Method = "POST"
submit = System.Text.Encoding.UTF8.GetBytes(content)
request.ContentType = "application/x-www-form-urlencoded,charset=utf-8"
request.ContentLength = submit.Length
dataStream = request.GetRequestStream()
dataStream.Write(submit, 0, submit.Length)
dataStream.Close()
response = request.GetResponse()
dataStream = response.GetResponseStream()
ms = New MemoryStream()
thisRead = 0
buff = New Byte(1023) {}
Do
thisRead = dataStream.Read(buff, 0, buff.Length)
If thisRead = 0 Then
Exit Do
End If
ms.Write(buff, 0, thisRead)
Loop While True
responseFromServer = ms.ToArray()
dataStream.Close()
response.Close()
statusCode = HttpStatusCode.OK
Catch ex As WebException
If ex.Response IsNot Nothing Then
dataStream = ex.Response.GetResponseStream()
Dim reader As New StreamReader(dataStream)
Dim resp As String = reader.ReadToEnd()
statusCode = DirectCast(ex.Response, HttpWebResponse).StatusCode
Else
resp = ""
statusCode = HttpStatusCode.ExpectationFailed
End If
Catch ex As Exception
statusCode = HttpStatusCode.ExpectationFailed
MsgBox(ex.Message)
End Try
Return responseFromServer
End Function
Appreciate for your help and support.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|