Загрузка...

Что я делаю не так?

Тема в разделе C# создана пользователем tipossilka77 9 июл 2021. 221 просмотр

Опрос

Я даун?

  1. Да

    3
    60%
  2. Нет

    2
    40%
  1. tipossilka77
    tipossilka77 Автор темы 9 июл 2021 rang: imperator 33 23 май 2020
    вот код python и из него надо сделать код c#
    Код
    def send_p2p(api_access_token, to_qw, comment, sum_p2p):
    s = requests.Session()
    s.headers = {'content-type': 'application/json'}
    s.headers['authorization'] = 'Bearer ' + api_access_token
    s.headers['User-Agent'] = 'Android v3.2.0 MKT'
    s.headers['Accept'] = 'application/json'
    postjson = {"id":"","sum":{"amount":"","currency":""},"paymentMethod":{"type":"Account","accountId":"643"}, "comment":"'+comment+'","fields":{"account":""}}
    postjson['id'] = str(int(time.time() * 1000))
    postjson['sum']['amount'] = sum_p2p
    postjson['sum']['currency'] = '643'
    postjson['fields']['account'] = to_qw
    res = s.post('https://edge.****.com/sinap/api/v2/terms/99/payments',json = postjson)
    return res.json()
    вот код с#
    Код
    private void Plata(string api_access_token, string to_qw, string sum_p2p, string num_volute)
    {
    Random rnd = new();
    int value = rnd.Next(1, 1000);

    string postjson = "{\"id\":\"\",\"sum\":{\"amount\":\"\",\"currency\":\"\"},\"paymentMethod\":{\"type\":\"Account\",\"accountId\":\"643\"}, \"comment\":\"None\",\"fields\":{\"account\":\"\"}}";
    postjson = postjson.Replace("id", Convert.ToInt32(value * 1000).ToString());
    postjson = postjson.Replace("amount", sum_p2p);
    postjson = postjson.Replace("currency", num_volute);
    postjson = postjson.Replace("account", to_qw);
    var httpRequest = (HttpWebRequest)WebRequest.Create("https://edge.****.com/sinap/api/v2/terms/99/payments");
    httpRequest.Method = "POST";
    httpRequest.ContentType = "application/json";
    httpRequest.Headers.Add("authorization", "Bearer " + api_access_token);
    httpRequest.Headers.Add("user-agent", "Android v3.2.0 MKT");
    using (var requestStream = httpRequest.GetRequestStream())
    using (var writer = new StreamWriter(requestStream))
    {
    writer.Write(postjson);
    }
    using (var httpResponse = httpRequest.GetResponse())
    using (var responseStream = httpResponse.GetResponseStream())
    using (var reader = new StreamReader(responseStream))
    {
    string response = reader.ReadToEnd();
    MessageBox.Show(response);
    }
    }
     
  2. tipossilka77
    tipossilka77 Автор темы 9 июл 2021 rang: imperator 33 23 май 2020
    При запросе выходит ошибка The remote server returned an error: (400) Bad Request.
     
  3. PeaceDeath
    Ты ключи в json'е заменяешь значениями, а значения остаются пустыми :thinking:
     
    1. tipossilka77 Автор темы
      @PeaceDeath, а как мне именно значения поменять?
Загрузка...
Top