通过JSON-RPC调用传递身份验证详细信息

I haven't been able to find any documentation on this. I need to make JSON-RPC calls to an API that requires (basic) authentication details to be passed, but can't find any way to do this with the standard net/rpc/jsonrpc package. A clipped version of my non-authenticating code is below.

var reply string
netClient, _ = net.Dial("tcp", "localhost:1234")
jsonClient = jsonrpc.NewClient(netClient)
jsonClient.Call("someMethod", someArgs, &reply)

Basic-Auth is an HTTP concept. Your code is opening a "raw" TCP connection to localhost:1234. What you need is an HTTP transport layer underneath.

There's two ways to accomplish what you want: either implement an HTTP-speaking io.ReadWriteCloser and use as in your example or implement an rpc.ClientCodec that does the HTTP basic auth and use in conjunction with rpc.NewClientWithCodec.