[英]C# Content.ReadAsAsync
As a form of study, I'm performing an integration with the Sandbox API of a payment gateway. 作为一种学习方式,我正在与支付网关的Sandbox API集成。 I am already able to perform the POST for the desired endpoint by passing the information in the Body + Headers.
我已经可以通过在Body + Headers中传递信息来执行所需端点的POST。 My question would be about using the Content.ReadAsAsync method to get the return of this POST.
我的问题是关于使用Content.ReadAsAsync方法获取此POST的返回值。 In response, I get a lot of information about the payment (including a GUID that identifies the transaction identifier).
作为回应,我获得了很多有关付款的信息(包括标识交易标识符的GUID)。
I'm trying to use Content.ReadAsAsync in the way below but I'm getting a "null" return. 我正在尝试以下面的方式使用Content.ReadAsAsync,但得到的是“空”返回。 Since it's the first time I do something like that, could you give me an idea of how to get the data together?
由于这是我第一次做这样的事情,您能给我一个如何将数据汇总在一起的想法吗?
Thanks in advance for your help. 在此先感谢您的帮助。
var transactionbuilder = new TransactionBuilder("300", customer, payment);
client.BaseAddress = new Uri("//ENDPOINT"); /
client.DefaultRequestHeaders.Add("//HEADER1");
client.DefaultRequestHeaders.Add("//HEADER2");
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.PostAsJsonAsync("//RESOURCE", transactionbuilder);
TransactionResponse exibeResponse = await response.Content.ReadAsAsync<TransactionResponse>();
Console.WriteLine(
$"{exibeResponse.AcquirerTransactionId}\n " +
$"{exibeResponse.AuthorizationCode}\n" +
$" {exibeResponse.PaymentId}\n" +
$" {exibeResponse.ProofOfSale}\n " +
$"{exibeResponse.ProviderReturnCode} \n" +
$"{exibeResponse.ProviderReturnMessage} \n" +
$"{exibeResponse.ReasonCode}\n " +
$"{exibeResponse.ReasonMessage}\n " +
$"{exibeResponse.ReceivedDate}\n " +
$"{exibeResponse.Status}"
);
Just to share, after the talk with @Yogu I solved it with the option below. 只是为了分享,在与@Yogu交谈之后,我通过以下选项解决了它。
HttpResponseMessage response = await client.PostAsJsonAsync("RESOURCE", transactionbuilder);
var content = await response.Content.ReadAsStringAsync();
dynamic formattedContent = JsonConvert.DeserializeObject<dynamic>(content);
var OrderPaymentId = formattedContent.Payment.PaymentId;
var OrderInstallments = formattedContent.Payment.Installments;
var OrderCapturedDate = formattedContent.Payment.CapturedDate;
Console.WriteLine($"" +
$"GUID: {OrderPaymentId}\n" +
$"Quantidade de Parcelas: {OrderInstallments}\n" +
$"Data de captura: {OrderCapturedDate}");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.