我有以下要在vb.net中实现的CURL命令。
curl -X POST "https://api.xxx.com/Auth/Key" -H "Content-Type: application/json-patch+json" -d "{ \"apiKey\": \"MyLongKey\", \"deviceUID\": \"string\"}".
上面的命令有效。
我将其实现为:
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
最后一行会产生错误:
System.Net.WebException HResult = 0x80131509 Message =基础 连接已关闭:发送中发生意外错误。
内部异常1:IOException:身份验证失败,因为 远程方已关闭传输流。