我一直试图在下面发送这个CURL命令,并尝试了一些示例,但没有一个工作,因为我需要发送用户名:密码,不知道这是一个HEADER,还有如何发送GET请求的身体。只是找一个发送用户密码的例子,因为无法在任何地方找到密码?
curl --data {"版本":" 1.1","方法":" room_verify"," params& #34; {"帐户" {"类型":"房间""值":" 0" --user test:test http://ressrv.worldweb.com:8001/json_pos_generic/22
这是我的代码:
Dim url As String = "http://ressrv.worldweb.com:8001/json_pos_generic/22"
Dim wrq = CType(Net.WebRequest.Create(url), HttpWebRequest)
Dim postString As String = "{""version"":""1.1"",""method"":""room_verify"",""params"":{""account"":{""type"":""room"",""value"":""0""}}}"
wrq.Method = "POST"
wrq.ContentType = "application/json"
wrq.ContentLength = postString.Length
wrq.Credentials = New NetworkCredential("test", "test")
Dim wrqWriter As New StreamWriter(wrq.GetRequestStream())
wrqWriter.Write(postString)
wrqWriter.Close()
Dim responseReader As New StreamReader(wrq.GetResponse().GetResponseStream())
Dim responseData As String = responseReader.ReadToEnd()
非常感谢任何帮助或指导...
答案 0 :(得分:0)
好的,我在尝试排序后的2天后找到了答案,虽然我使用了稍微不同的代码,但我认为这完全取决于我的凭据是否转换为Base64,我现在要研究为什么这是必需的。我在另一篇文章Curl request equivalent in VB.NET
中找到了这个答案 Dim myReq As HttpWebRequest
Dim myResp As HttpWebResponse
myReq = HttpWebRequest.Create("http://ressrv.worldweb.com:8001/json_pos_generic/22")
myReq.Method = "POST"
myReq.ContentType = "application/json"
myReq.Headers.Add("Authorization", "Basic " & Convert.ToBase64String(Encoding.UTF8.GetBytes("test:test")))
Dim myData As String = "{""version"":""1.1"",""method"":""room_verify"",""params"":{""account"":{""type"":""room"",""value"":""0""}}}"
myReq.GetRequestStream.Write(System.Text.Encoding.UTF8.GetBytes(myData), 0, System.Text.Encoding.UTF8.GetBytes(myData).Count)
myResp = myReq.GetResponse
Dim myreader As New System.IO.StreamReader(myResp.GetResponseStream)
Dim myText As String
myText = myreader.ReadToEnd
MsgBox(myText)
非常感谢!!