Json 带VBnet的bitfinexapi

Json 带VBnet的bitfinexapi,json,vb.net,encoding,Json,Vb.net,Encoding,以下是我到目前为止得出的结论: Sub GetData() Try Dim method As String = calldata("/balances") MsgBox(method) Catch ex As Exception End Try End Sub Function calldata(ByVal Method As String) As String Dim logincookie As CookieContaine

以下是我到目前为止得出的结论:

Sub GetData()
Try

        Dim method As String = calldata("/balances")
        MsgBox(method)

    Catch ex As Exception

    End Try
End Sub

Function calldata(ByVal Method As String) As String

    Dim logincookie As CookieContainer


    Try
        Dim pKey As String = "CODE HERE"
        Dim sKey As String = "SECRET CODE HERE"

        Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("https://api.bitfinex.com/v1/"), HttpWebRequest)
        Dim randomn As String = CLng(DateTime.UtcNow.Subtract(New DateTime(1970, 1, 1)).TotalSeconds)

        '//Dependant upon Method
        Dim postData As String = "method=" & Method & "&nonce=" & randomn
        Dim tempcookies As New CookieContainer

        '//Start Encryption
        Dim KeyByte() As Byte = Encoding.ASCII.GetBytes(sKey)
        Dim HMAcSha As New HMACSHA384(Encoding.ASCII.GetBytes(sKey))

        Dim messagebyte() As Byte = Encoding.ASCII.GetBytes(postData)
        Dim hashmessage() As Byte = HMAcSha.ComputeHash(messagebyte)
        Dim Sign As String = BitConverter.ToString(hashmessage)

        Sign = Sign.Replace("-", "")

        '//Generate Post Information
        postReq.Method = "POST"
        postReq.KeepAlive = False
        postReq.Headers.Add("X-BFX-APIKEY", pKey)
        postReq.Headers.Add("X-BFX-PAYLOAD")
        postReq.Headers.Add("X-BFX-SIGNATURE", LCase(Sign))
        postReq.CookieContainer = tempcookies

        postReq.ContentType = "application/x-www-form-urlencoded"
        postReq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)"
        postReq.ContentLength = messagebyte.Length

        '//Send Request
        System.Net.ServicePointManager.Expect100Continue = False

        Dim postreqstream As Stream = postReq.GetRequestStream()
        postreqstream.Write(messagebyte, 0, messagebyte.Length)
        postreqstream.Close()
        Dim postresponse As HttpWebResponse

        postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
        tempcookies.Add(postresponse.Cookies)
        logincookie = tempcookies

        Dim postreqreader As New StreamReader(postresponse.GetResponseStream())

        'The Response Text
        Dim thepage As String = postreqreader.ReadToEnd
        thepage = thepage.Replace(Chr(34), Chr(39))

        Return thepage

    Catch
        Return False

    End Try


End Function
我想不出有效载荷的部分。这个脚本是我用于其他API的修改版本。以下是Bitfinex API信息

除了付帐外,一切都好吗?如何完成API详细信息中的“payload=parameters dictionary->JSON encode->base64”部分

Sub GetData()

        Try
            Dim method As String = calldata("/balances")
            MsgBox(method)


        Catch ex As Exception

        End Try
End Sub


    Function calldata(ByVal Method As String) As String

        Dim logincookie As CookieContainer


        Try
            Dim pKey As String = "CODE HERE"
            Dim sKey As String = "SECRET CODE HERE"

            Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("https://api.bitfinex.com/v1/balances"), HttpWebRequest)
            Dim randomn As String = CLng(DateTime.UtcNow.Subtract(New DateTime(1970, 1, 1)).TotalSeconds)

            '//Dependant upon Method
            Dim postData As String = "{""request"": ""/v1" & Method & """,""nonce"": """ & randomn & """,""options"":{}}"
            Dim tempcookies As New CookieContainer
            Dim payload As String = Convert.ToBase64String(Encoding.UTF8.GetBytes(postData))

            '//Start Encryption
            Dim KeyByte() As Byte = Encoding.ASCII.GetBytes(sKey)
            Dim HMAcSha As New HMACSHA384(Encoding.ASCII.GetBytes(sKey))
            Dim messagebyte() As Byte = Encoding.ASCII.GetBytes(payload)
            Dim hashmessage() As Byte = HMAcSha.ComputeHash(messagebyte)
            Dim Sign As String = BitConverter.ToString(hashmessage)

            Sign = Sign.Replace("-", "")

            '//Generate Post Information
            postReq.Method = "POST"
            postReq.KeepAlive = False
            postReq.Headers.Add("X-BFX-APIKEY", pKey)
            postReq.Headers.Add("X-BFX-PAYLOAD", payload)
            postReq.Headers.Add("X-BFX-SIGNATURE", LCase(Sign))
            postReq.CookieContainer = tempcookies

            postReq.ContentType = "application/x-www-form-urlencoded"
            postReq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)"
            postReq.ContentLength = messagebyte.Length

            '//Send Request
            System.Net.ServicePointManager.Expect100Continue = False

            Dim postreqstream As Stream = postReq.GetRequestStream()
            postreqstream.Write(messagebyte, 0, messagebyte.Length)
            postreqstream.Close()
            Dim postresponse As HttpWebResponse

            postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
            tempcookies.Add(postresponse.Cookies)
            logincookie = tempcookies

            Dim postreqreader As New StreamReader(postresponse.GetResponseStream())

            'The Response Text
            Dim thepage As String = postreqreader.ReadToEnd
            thepage = thepage.Replace(Chr(34), Chr(39))

            Return thepage

        Catch e As Exception
            Return False

        End Try

    End Function

请解释您答案中的代码是什么,以便新接触相关技术的人员有机会理解并重新使用它:-)