HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://edge.qiwi.com/sinap/api/v2/terms/99/payments");
request.Method = "POST";
request.Headers["authorization"] = "Bearer " + token;
request.ContentType = "application/json; charset=utf-8";
string sQueryString = json;
byte[] ByteArr = Encoding.ASCII.GetBytes(sQueryString);
request.ContentLength = ByteArr.Length;
request.GetRequestStream().Write(ByteArr, 0, ByteArr.Length);
string html = string.Empty;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (StreamReader myStreamReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
html = myStreamReader.ReadToEnd();
MessageBox.Show(html);
}
}
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.Json;
var json = new
{
id = "11111111111111",
sum = new {amount = 100, currency = "643"},
paymentMethod = new {type = "Account", accountId = "643"},
comment = "test",
fields = new {account = "+79121112233"}
};
var token = "YUu2qw048gtdsvlk3iu";
using var httpClient = new HttpClient();
using var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri("https://edge.qiwi.com/sinap/api/v2/terms/99/payments"),
Headers =
{
Accept = {MediaTypeWithQualityHeaderValue.Parse("application/json")},
Authorization = AuthenticationHeaderValue.Parse("Bearer " + token)
},
Content = new StringContent(JsonSerializer.Serialize(json))
{
Headers = {ContentType = MediaTypeHeaderValue.Parse("application/json")}
}
};
var response = await httpClient.SendAsync(request);
var responseText = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseText);