C# most siple JSON request

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ShootnikD
    Junior Member
    • Oct 2012
    • 11

    #1

    C# most siple JSON request

    Hello. Can anybody explain what wrong with code:
    Code:
            static public void TestMethod()
            {
                string Url = "https://api.betfair.com/";  // <-????
                WebRequest request = null;
                WebResponse response = null;
                string strResponseStatus = "";
                request = WebRequest.Create(new Uri(Url));
                request.Method = "POST";
                request.ContentType = "application/json-rpc";
                request.Headers.Add(HttpRequestHeader.AcceptCharset, "ISO-8859-1,utf-8");
                request.Headers.Add("X-Authentication", *****);
                request.Headers.Add("X-Application", ****);
                using (var streamWriter = new StreamWriter(request.GetRequestStream()))
                {
                    string json = "{\"jsonrpc\": \"2.0\",\"method\": \"SportsAPING/v1.0/listEventTypes\",\"params\": {\"filter\": {}},\"id\": 1}";
                    streamWriter.Write(json);
                }
                response = request.GetResponse();
                using (var streamReader = new StreamReader(response.GetResponseStream()))
                {
                    var responseText = streamReader.ReadToEnd();
                }
                response.Close();
            }
    responseText is epmty
  • tkw141
    Junior Member
    • Nov 2013
    • 18

    #2
    Hi,
    Your url doesn't look complete.
    Have you tried:
    https://api.betfair.com/exchange/betting/json-rpc/v1

    Comment

    • tkw141
      Junior Member
      • Nov 2013
      • 18

      #3
      I'm not familiar with C# but your json string is slightly different to mine

      json = {"params":{"filter":{}},"id":1,"method":"SportsAPI NG/v1.0listEventTypes"}

      No spaces after the :
      and no "jsonrpc\": \"2.0\

      Comment

      • tkw141
        Junior Member
        • Nov 2013
        • 18

        #4
        Originally posted by tkw141 View Post
        I'm not familiar with C# but your json string is slightly different to mine

        json = {"params":{"filter":{}},"id":1,"method":"SportsAPI NG/v1.0listEventTypes"}

        No spaces after the :
        and no "jsonrpc\": \"2.0\
        Ignore this...just tested it with the Visualiser and it sends this json request
        {"jsonrpc": "2.0", "method": "SportsAPING/v1.0/listEventTypes", "params": {"filter":{}}, "id": 1}

        so spaces and "jsonrpc": "2.0" are okay

        Comment

        • ShootnikD
          Junior Member
          • Oct 2012
          • 11

          #5
          Originally posted by tkw141 View Post
          Hi,
          Your url doesn't look complete.
          Have you tried:
          https://api.betfair.com/exchange/betting/json-rpc/v1
          Working. Thank you

          Comment

          Working...
          X