douyan6742
douyan6742
2012-01-31 04:24

GAE Golang-HTTP JSON RPC调用可在dev_appserver中使用,但不能在App Engine上使用?

已采纳

I'm creating a Go Google App Engine application that will be making HTTP JSON RPC calls to a Bitcoin server. I got my code to work properly on the dev_appserver, but when deployed on GAE, the code seems to not work. I'm using a library available on GitHub, and call it like this:

func GetInfo(id interface{})(map[string]interface{}, os.Error){
    resp, err:=httpjsonrpc.Call("user:pass@111.1.1.1:18332", "getinfo", id, nil)
    if err!=nil{
        log.Println(err)
        return resp, err
    }
    return resp, err
}

Which when called should give:

map[proxy: keypoololdest:1.327368259e+09 blocks:45385 keypoolsize:101 connections:11 version:50200 difficulty:8.88353262 generate:false hashespersec:0 paytxfee:0 balance:0 genproclimit:-1 testnet:true errors:]

But on GAE calling the function seems to be causing an error. What part of the code could be working on dev_appserver, but fail on GAE?

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

1条回答

  • doushansu9012 doushansu9012 9年前

    You should make you are using urlfetch.Transport to make HTTP calls in production as described in urlfetch documentation.

    Instead of doing:

    resp, err := http.Post(address,
        "application/json", strings.NewReader(string(data)))
    

    You should be doing:

    client := urlfetch.Client(context)
    resp, error := client.Post(address,
        "application/json", strings.NewReader(string(data)))
    

    As you can see in the implementation, urlfetch.Client is just a shortcut to construct an http.Client that uses urlfetch.Transport.

    点赞 评论 复制链接分享

相关推荐