JSON请求错误Mollybet API

时间:2019-01-02 13:21:46

标签: c# json rest unicode django-rest-framework

我们在第4.3.1节中遇到问题,使用API​​ https://api.mollybet.com/docs/v1/#create-a-new-bet-placement-order创建新的下注顺序。

使用的客户端是c#Httpclient,我们将参数作为JSON主体发送。

{
   "betslip_id":"aff87f1773774ef7b04e81992c038e8f",
   "price":"2.06",
   "stake":"[\"EUR\", 13]",
   "duration":"15",
   "accounts":"[\"ibc\", \"_99899bb2_\"]",
   "adaptive_bookies":"[ibc]",
   "ignore_system_maintenance":false,
   "no_put_offer_exchange":false,
   "bookie_min_stakes":"{}",
   "user_data":null
}

validation_errors

请参阅屏幕截图:

我们无法超越这一步,我们将不胜感激。

编辑-生成dbc要求的JSON的代码:

    private void doPlace(string betSlipId,double price , double stake , string bookie, string accountName)
    {
        try
        {
            //string placebetLink = "https://pro.sportmarket.com/trade/place_order";
            //var postData = new FormUrlEncodedContent(new[]
            //{
            //    new KeyValuePair<string,string>("betslip_id",betSlipId),
            //    new KeyValuePair<string,string>("price" , price.ToString()),
            //    new KeyValuePair<string, string>("request_uuid",getRandom()),
            //    new KeyValuePair<string, string>("timeout","20"),
            //    new KeyValuePair<string,string>("stake",stake.ToString()),
            //    new KeyValuePair<string,string>("accounts",accountName),
            //    new KeyValuePair<string,string>("adaptive",bookie),
            //    new KeyValuePair<string, string>("ignore_autoplacing","false"),
            //    new KeyValuePair<string, string>("csrfmiddlewaretoken", csrToken)
            //});

            //HttpResponseMessage placeResponse = httpClient.PostAsync(placebetLink, postData).Result;
            //placeResponse.EnsureSuccessStatusCode();

            //string content = placeResponse.Content.ReadAsStringAsync().Result;
            //ApiClient.DefaultRequestHeaders.TryAddWithoutValidation("X-Requested-With", "XMLHttpRequest");
            httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json");
            string stakeStr = string.Format("[\"EUR\", {0}]", stake);
            string placebetUrl = string.Format("{0}v1/orders/", endPonit);
            //var postData = new FormUrlEncodedContent(new[]
            //{
            //    new KeyValuePair<string,string>("betslip_id",betSlipId),
            //    new KeyValuePair<string,string>("price" , price.ToString()),
            //    new KeyValuePair<string,string>("stake",stakeStr),
            //    new KeyValuePair<string,string>("duration","15"),
            //    new KeyValuePair<string,string>("accounts",accountName),
            //    new KeyValuePair<string,string>("adaptive_bookies",string.Format("[{0}]",bookie)),
            //    new KeyValuePair<string, string>("ignore_system_maintenance","false"),
            //    new KeyValuePair<string, string>("no_put_offer_exchange","false"),
            //    new KeyValuePair<string, string>("bookie_min_stakes","{}"),
            //    new KeyValuePair<string, string>("user_data","")

            //});

            PlaceRequest requestJson = new PlaceRequest();
            requestJson.betslip_id = betSlipId;
            requestJson.price = price.ToString();
            requestJson.stake = stakeStr;
            requestJson.accounts = accountName;
            requestJson.duration = "15";
            requestJson.adaptive_bookies = string.Format("[{0}]", bookie);
            requestJson.ignore_system_maintenance = false;
            requestJson.no_put_offer_exchange = false;
            requestJson.bookie_min_stakes = "{}";

            string jsonStr = JsonConvert.SerializeObject(requestJson);

            HttpResponseMessage placeResponse = ApiClient.PostAsync(placebetUrl, new StringContent(jsonStr, Encoding.UTF8, "application/json")).Result;
            placeResponse.EnsureSuccessStatusCode();

            string content = placeResponse.Content.ReadAsStringAsync().Result;
        }
        catch (Exception e)
        {

        }

    }

0 个答案:

没有答案