dongtu1357 2018-05-31 09:46
浏览 324

通过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)
  • 写回答

1条回答 默认 最新

  • dpkrh2444 2018-05-31 14:58
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 武汉岩海低应变分析软件,导数据库里不显示波形图
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。
  • ¥30 win c++ socket
  • ¥30 CanMv K210开发板实现功能
  • ¥15 C# datagridview 栏位进度
  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web
  • ¥15 kali环境运行volatility分析android内存文件,缺profile
  • ¥15 写uniapp时遇到的问题
  • ¥15 vs 2008 安装遇到问题