Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added suport for JSON-RPC 2.0 in jsonlib #5

Open
GoogleCodeExporter opened this issue May 3, 2016 · 0 comments
Open

Added suport for JSON-RPC 2.0 in jsonlib #5

GoogleCodeExporter opened this issue May 3, 2016 · 0 comments

Comments

@GoogleCodeExporter
Copy link

Public Function JsonRpcCall(url As String, methName As String, args(),
Optional user As String, Optional pwd As String) As Object
    Dim r As Object, cli As MSXML2.XMLHTTP60
    Dim pText As String
    Static reqId As Integer

    reqId = reqId + 1

    Set r = CreateObject("Scripting.Dictionary")
    r("jsonrpc") = "2.0"
    r("method") = methName
    r("params") = args
    r("id") = reqId

    pText = toString(r)

    ''Set cli = CreateObject("MSXML2.XMLHTTP.6.0")
    Set cli = New MSXML2.XMLHTTP60
    If Len(user) > 0 Then   ' If Not IsMissing(user) Then
        cli.Open "POST", url, False, user, pwd
    Else
        cli.Open "POST", url, False
    End If
    cli.setRequestHeader "Content-Type", "application/json"
    cli.Send pText

    If cli.Status <> 200 Then
        Err.Raise vbObjectError + INVALID_RPC_CALL + cli.Status, ,
cli.statusText
    End If

    Set r = parse(cli.responseText)
    Set cli = Nothing

    If r("id") <> reqId Then Err.Raise vbObjectError + INVALID_RPC_CALL, ,
"Bad Response id"

    If r.Exists("error") Or Not r.Exists("result") Then
        Err.Raise vbObjectError + INVALID_RPC_CALL, , "Json-Rpc Response
error: " & r("error")("message")
    End If

    If Not r.Exists("result") Then Err.Raise vbObjectError +
INVALID_RPC_CALL, , "Bad Response, missing result"

    Set JsonRpcCall = r("result")
End Function



Original issue reported on code.google.com by [email protected] on 16 Jun 2009 at 11:48

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant