Curl request into vb.net

0

I have the following CURL command that I'm trying to implement in vb.net.

curl -X POST "https://api.xxx.com/Auth/Key"  -H "Content-Type: application/json-patch+json" -d "{ \"apiKey\": \"MyLongKey\", \"deviceUID\": \"string\"}". 

The command above works.

I've implemented this as:

Dim myReq As HttpWebRequest
Dim myResp As HttpWebResponse

myReq = HttpWebRequest.Create("https://api.xxx.com/Auth/Key")
myReq.Method = "POST"
myReq.ContentType = "application/json"
myReq.Accept = "text/plain"
Dim myData As String = "{""apiKey"": ""MyLongKey"", ""deviceUID"": ""string""}"

myReq.GetRequestStream.Write(System.Text.Encoding.UTF8.GetBytes(myData), 0, 
                                           System.Text.Encoding.UTF8.GetBytes(myData).Count)
myResp = myReq.GetResponse

The final line creates an error:

System.Net.WebException HResult=0x80131509 Message=The underlying connection was closed: An unexpected error occurred on a send.
Inner Exception 1: IOException: Authentication failed because the remote party has closed the transport stream.

json
vb.net
curl
asked on Stack Overflow Apr 15, 2020 by Dan • edited Apr 15, 2020 by MatSnow

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0