【问题标题】:json-rpc server over nancynancy 上的 json-rpc 服务器
【发布时间】:2014-03-02 22:21:54
【问题描述】:

我们已经开始在我们的开源项目中使用 nancy; https://github.com/CoiniumServ/coinium(一个层/getwork/gbt 池服务器)。

我们基本上需要支持 json-rpc 上的 api 调用。我们收到了类似的请求;

        HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(Url);
        webRequest.Credentials = new NetworkCredential(User, Password);
        webRequest.ContentType = "application/json-rpc";
        webRequest.Method = "POST";

        string jsonParam = (paramString != null) ? "\"" + paramString + "\"" : "";
        string request = "{\"id\": 0, \"method\": \"" + method + "\", \"params\": [" + jsonParam + "]}";

        // serialize json for the request
        byte[] byteArray = Encoding.UTF8.GetBytes(request);
        webRequest.ContentLength = byteArray.Length;
        using (Stream dataStream = webRequest.GetRequestStream())
            dataStream.Write(byteArray, 0, byteArray.Length);

        string reply = "";
        using (WebResponse webResponse = webRequest.GetResponse())
        using (Stream str = webResponse.GetResponseStream())
        using (StreamReader reader = new StreamReader(str))
            reply = reader.ReadToEnd();

        return reply;

所以基本上请求被发送到 / 路由,内容类型为 application/json-rpc,我们需要解析内部提供的请求。

我检查了文档但找不到出路,nancy 是否支持 json-rpc?

谁能指出我正确的方向?

我已将示例路线设为;

        Post["/"] = @params =>
        {
            return "test";
        };

但在 @params 或 Context 中找不到要解析的实际 json-rpc 请求字符串。

【问题讨论】:

    标签: c# nancy json-rpc


    【解决方案1】:

    尝试模型绑定 (https://github.com/NancyFx/Nancy/wiki/Model-binding) 或直接查看 Request.Body。

    【讨论】:

      猜你喜欢
      • 2011-02-05
      • 2011-02-07
      • 2012-08-19
      • 1970-01-01
      • 2013-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多