Проблема с отправкой вызова json -rp c через vb.net - PullRequest
0 голосов
/ 10 июля 2020

Я пытаюсь отправить сообщение на локальный bitcoin полный узел через json -rp c, но я ничего не получаю от сервера.

Следуя документации здесь

Мой код отлично работает с getblockcount

вот так:

  Private Sub button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click

        RichTextBox5.Text = RequestServer("getblockcount", New List(Of JToken))
    
   End Sub

Но когда я пытаюсь передать вызов с параметрами, блок catch возвращает ошибку 500 с сервера

Мой код для звонка с параметрами:

 Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

       
        Dim s As JToken = "'[{""txid"":""0000000000000000000000000000000000000000000000000000000000000000"",""vout"":0}]'"
        Dim ss As JToken = "'{""bc1q5t4sexcufx9ecnepfd4v88j8fvq3q5ymzetmqt"":6.5}'"

        RichTextBox5.Text = RequestServer("createrawtransaction", New List(Of JToken) From {s, ss})
          End Sub

Функция RequestServer:

 Public Shared Function RequestServer(ByVal methodName As String, ByVal parameters As List(Of JToken)) As JToken
        Dim ServerIp As String = "http://localhost:8332"
        Dim UserName As String = "hama"
        Dim Password As String = "hama"
        Dim webRequest As HttpWebRequest = CType(webRequest.Create(ServerIp), HttpWebRequest)
        webRequest.Credentials = New NetworkCredential(UserName, Password)

        webRequest.ContentType = "application/json-rpc"
        webRequest.Method = "POST"


        Dim respVal As String = String.Empty
        Dim joe As JObject = New JObject
        joe.Add(New JProperty("jsonrpc", 1))
        joe.Add(New JProperty("id", 1))
        joe.Add(New JProperty("method", methodName))
        Dim props As JArray = New JArray
        For Each parameter In parameters
            props.Add(parameter)
        Next
        joe.Add(New JProperty("params", props))
        ' serialize json for the request
        Dim s As String = JsonConvert.SerializeObject(joe)
        Dim byteArray() As Byte = Encoding.UTF8.GetBytes(s)
        webRequest.ContentLength = byteArray.Length
        Dim dataStream As Stream = webRequest.GetRequestStream
        dataStream.Write(byteArray, 0, byteArray.Length)
        dataStream.Close()
        Dim streamReader As StreamReader = Nothing
        Try
            Dim webResponse As WebResponse = webRequest.GetResponse
            streamReader = New StreamReader(webResponse.GetResponseStream, True)
            respVal = streamReader.ReadToEnd
            Dim data = JsonConvert.DeserializeObject(respVal).ToString
            Return data
        Catch exp As Exception
MsgBox(exp.ToString)

        Finally
            If (Not (streamReader) Is Nothing) Then
                streamReader.Close()
            End If

        End Try

        Return String.Empty


    End Function

Помощь будет оценена, спасибо

...