0

We've started using nancy in our open source project; https://github.com/CoiniumServ/coinium (a stratum/getwork/gbt pool server).

We basically need to support api calls over json-rpc. We're getting request similar to this;

        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;

So basically the request is sent to / route with content-type application/json-rpc and we need to parse the inner provided request.

I've checked documentation but couldn't find my way out, does nancy support json-rpc?

Can anybody point me to right direction?

I've put a sample route as;

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

but within the @params or Context couldn't find the actual json-rpc request string to parse.

HuseyinUslu
  • 4,094
  • 5
  • 33
  • 50

1 Answers1

1

Try either model binding (https://github.com/NancyFx/Nancy/wiki/Model-binding) or looking at Request.Body directly.

Christian Horsdal
  • 4,914
  • 23
  • 24