如何从ASP.NET C#中的URL使用json get方法获取响应 [英] How to get response using json get method from a URL in ASP.NET C#
问题描述
我发布了一个json字符串进行付款,付款后重定向到我的成功页面,
在我的成功页面上我需要获取交易详情
按照付款文件我需要使用json Get Method来获取交易细节,传递代码如
I post a json string for payment , after payment it redirects to my success page,
On my success page i need get transaction details
So as per Payment Documentation i need use json Get Method to get the transaction details , passing a code like
"https://sb-open.revenuemonster.my/v3/payment/transaction/qrcode/" + Session["QrCodeWc"].ToString() + "/transactions"
示例链接下面可以看到此网址上的Json数据
https://sb-open.revenuemonster.my/v3/payment/transaction/qrcode / c6c2df354c1e5274a1adc462ffbd96b3 / transactions [ ^ ]
我把代码放在会话中
现在我想知道如何把代码写到Ge t方法从上面的URL获得回复
这是文件Instuction
Example Link Below can see Json data on this url
https://sb-open.revenuemonster.my/v3/payment/transaction/qrcode/c6c2df354c1e5274a1adc462ffbd96b3/transactions[^]
where i put code trough Session
Now i want to know how to write code to Get method to get responses from above URL
This is document Instuction
GET Get Transactions By Code
https://sb-open.revenuemonster.my/v3/payment/transaction/qrcode/39d1f014eade17aa77fb2aaa6a4e6afb/transactions
To get all transactions under existing QR code, by passing in code in query parameter (/qrcode/.../transactions).
REQUEST
Request Parameters:
Note: No request parameter is required for this endpoint
感谢任何帮助
我尝试过:
Appreciate any help
What I have tried:
string reqUrl = "https://sb-open.revenuemonster.my/v3/payment/transaction/qrcode/" + Session["QrCodeWc"].ToString() + "/transactions";
var httpWebRequestQR = (HttpWebRequest)WebRequest.Create(reqUrl);
httpWebRequestQR.ContentType = "application/json";
httpWebRequestQR.Method = "GET";
using (var streamWriterQR = new
StreamWriter(httpWebRequestQR.GetRequestStream()))
{
string jsonQR = new JavaScriptSerializer().Serialize(new
{
});
streamWriterQR.Write(jsonQR);
}
var httpResponseQR = (HttpWebResponse)httpWebRequestQR.GetResponse();
using (var streamReader = new StreamReader(httpResponseQR.GetResponseStream()))
{
var resultsign = streamReader.ReadToEnd();
string jsonStringsign = resultsign;
JsonData json = JsonMapper.ToObject(jsonStringsign);
string tranId = json["item"]["transactionId"].ToString();
lblMsg.Text = tranId;
}
推荐答案
如果您返回了JSON数据,请阅读本文,因为它是为了回答Q& A而写的这些问题:在C#中使用JSON& VB [ ^ ]
If you have the JSON data returned, then read this article as it was written to answer Q&A questions like these: Working with JSON in C# & VB[^]
我解决了这个问题,一旦使用获取方法就不需要添加Get Streams
以下是解决方案。
I solved the issue, No need to add Get Streams once use Get Methods
Here are the solutions.
var httpWebRequestQR = (HttpWebRequest)WebRequest.Create(reqUrl);
httpWebRequestQR.ContentType = "application/json";
httpWebRequestQR.Method = "GET";
httpWebRequestQR.Headers.Add("Authorization", "Bearer " + accToken);
httpWebRequestQR.Headers.Add("X-Signature", signatureWc);
httpWebRequestQR.Headers.Add("X-Nonce-Str", nonce);
httpWebRequestQR.Headers.Add("X-Timestamp", timestampStr);
var httpResponseQR = (HttpWebResponse)httpWebRequestQR.GetResponse();
using (var streamReader = new StreamReader(httpResponseQR.GetResponseStream()))
{
var resultQR = streamReader.ReadToEnd();
string jsonStringsign = resultQR;
JsonData json = JsonMapper.ToObject(jsonStringsign);
string txnId = json["items"]["transactionId"].ToString();
string storeId = json["items"]["store"]["id"].ToString();
string curType = json["items"]["currencyType"].ToString();
int ttfee = (int) json["items"]["order"]["amount"];
}
这篇关于如何从ASP.NET C#中的URL使用json get方法获取响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!