2011-07-06 14:27


package main

import "rpc/jsonrpc"
import "fmt"

func main() {
    rc, e := jsonrpc.Dial("tcp", "user:pass@localhost:8332")
    if e != nil {fmt.Print(e);return;}

    var blocks float64
    rc.Call("getblockcount", "", &blocks)
    if e != nil {fmt.Print(e); return;}
    fmt.Print("%f blocks", blocks)

Gives me the following error: dial tcp user:pass@localhost:8332: too many colons in address user:pass@localhost:8332

How do I authenticate my rpc connection?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • doupaoshu8334 doupaoshu8334 10年前
    testRequest := `{"jsonrpc": "1.0", "id":"", "method": "help", "params": []}`
    request, e := http.NewRequest("POST", brpc.addr, strings.NewReader(testRequest))
    request.SetBasicAuth(brpc.user, brpc.pass)
    responce, e := brpc.c.Do(request)
    // responce.Body has the result
    点赞 评论 复制链接分享
  • dsjz1119 dsjz1119 10年前

    The Go rpc/jsonrpc package (and more generally, the rpc package) does not support authentication. A valid string for the jsonrpc.Dial can be found in the documentation for the second argument of the underlying net.Dial function.

    But I think you're also making a big assumption that whatever system you're trying to connect to (bitcoin maybe?) supports the Go jsonrpc protocol, which--unless it's written in Go--it almost assuredly does not.

    点赞 评论 复制链接分享