我有一个python代码。我需要它的 vb.net 等价物。
提前致谢。
payload2 = {"auth_token": "YOUR_AUTH_TOKEN", "status":"green", "data-title1":"index", "data-title2":"machine1", "data-title3":"package10", "data-title4":"current", "data-title5":"tmp"}
r=requests.post("http://localhost:3030/widgets/hot21",data=json.dumps(payload2))
额外信息 代码在“UiPath社区版”中被调用
最后的代码(感谢 JussiV)是
Imports System.Text
Dim payload2 As New Dictionary(Of String, String)
payload2.Add("auth_token", "YOUR_AUTH_TOKEN")
payload2.Add("status", "green")
payload2.Add("data-title1", "index")
payload2.Add("data-title2", "machine1")
payload2.Add("data-title3", "package10")
payload2.Add("data-title4", "current")
payload2.Add("data-title5", "tmp")
Dim params As String = JsonConvert.SerializeObject(payload2, Formatting.None)
Dim Uri As New Uri(String.Format("http://10.10.115.99:3030/widgets/hot21"))
Dim webClient As New WebClient()
Dim resByte As Byte()
Dim resString As String
Dim reqString() As Byte
webClient.Headers("content-type") = "application/json"
Dim senddata As Object = JsonConvert.SerializeObject(New With {Key .param = params}).ToString()
reqString = Encoding.Default.GetBytes(senddata)
resByte = webClient.UploadData(Uri, "post", reqString)
resString = Encoding.Default.GetString(resByte)
最后的错误消息是
webservice has thrown an exception
Source: Invoke code
Message: Error compiling code
error BC30035: syntax error. At line 1
error BC30561: 'Formatting' is ambiguous, imported from the namespaces or types 'Newtonsoft.Json, System.Xml'. At line 10
error BC30002: Type 'WebClient' is not defined. At line 12
error BC30451: 'Encoding' is not declared. It may be inaccessible due to its protection level. At line 18
error BC30451: 'Encoding' is not declared. It may be inaccessible due to its protection level. At line 20
Exception Type: ArgumentException