如何在C#中立即获取请求和响应 [英] How to get request and response immediately in C#

查看:84
本文介绍了如何在C#中立即获取请求和响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的要求是:



< pre> string FormName =frmTransaction; 
string Method =post;
string V3URL =https://api.secure.ebs.in/api/1_0;
Response.Clear();
Response.Write(< html>< head>);

Response.Write(string.Format(< / head>< body onload = \document。{0} .submit()\>,FormName));
Response.Write(string.Format(< form name = \{0} \method = \{1} \action = \{2} \> ;,FormName,Method,V3URL));

Response.Write(< input type = \hidden \name = \TransactionID \value =+ Request.QueryString [TransId] +/> ;);
Response.Write(< input type = \hidden \name = \SecretKey \value =+ ApplicationConfig.EbsSecretKey +/>);
Response.Write(< input type = \hidden \name = \AccountID \value =+ ApplicationConfig.EbsAccountId +/>);
Response.Write(< input type = \hidden \name = \PaymentID \value =+ Request.QueryString [PayMId] +/>);
Response.Write(< input type = \hidden \name = \Action \value = \status \/>);
Response.Write(< / form>);
Response.Write(< / body>< / html>);
Response.End();



我的输出描述如下:

< output accountId = testamount =500.00billingAddress =IndiabillingCity =NamakkalbillingCountry =INDbillingEmail =admin@gmail.combillingName =availbillingPhone =xxxxbillingPostalCode =600001billingState =Tnadu dateCreated =2018-05-16 11:58:22deliveryAddress =deliveryCity =deliveryCountry =INRdeliveryName =deliveryPhone =xxxxxxxxxdeliveryPostalCode =deliveryState =description =gwAuthId =0000gwReciptNo =0000isFlagged =NOmode =TESTpaymentId =102591103paymentMethod =1001paymentMode =Credit Cardprocessed =YesreferenceNo =17181status =Captured transactionId =302443643/> 





我尝试过:



我需要从这个页面检查交易状态如何检查。请提供样品代码。你可以帮忙立即获得输出谢谢

解决方案

你不能将输出转换成C#代码 - C#是一种编程语言,而不是数据库。

你有什么看起来像是XML数据的片段 - 有可能设计一个类来保存这些数据,但数据本身不能转换为代码本身。

你的代码正在做的是使html导致浏览器请求url并显示结果,但这不是你想要的,你希望你的代码隐藏请求url并获得结果。要做到这一点,你需要以编程方式POST到url。请查看以下链接中的HttpClient帖子代码



C# - 执行Http GET和POST请求的几种方法Yusuf Setiawan的博客 [ ^ ]



您的价值字典将是



TransactionID,Request.QueryString [TransId],
//在此处添加其余的key\value对


My Request is :

<pre> string FormName = "frmTransaction";
                string Method = "post";
                string V3URL = "https://api.secure.ebs.in/api/1_0";
                Response.Clear();
                Response.Write("<html><head>");

                Response.Write(string.Format("</head><body onload=\"document.{0}.submit()\">", FormName));
                Response.Write(string.Format("<form name=\"{0}\" method=\"{1}\" action=\"{2}\" >", FormName, Method, V3URL));

                Response.Write("<input type=\"hidden\" name=\"TransactionID\" value=" + Request.QueryString["TransId"] + " />");
                Response.Write("<input type=\"hidden\" name=\"SecretKey\" value=" + ApplicationConfig.EbsSecretKey + " />");
                Response.Write("<input type=\"hidden\" name=\"AccountID\" value=" + ApplicationConfig.EbsAccountId + " />");
                Response.Write("<input type=\"hidden\" name=\"PaymentID\" value=" + Request.QueryString["PayMId"] + " />");
                Response.Write("<input type=\"hidden\" name=\"Action\" value=\"status\" />");
                Response.Write("</form>");
                Response.Write("</body></html>");
                Response.End();


My Output descriped below:

<output accountId="test" amount="500.00" billingAddress="India " billingCity="Namakkal" billingCountry="IND" billingEmail="admin@gmail.com" billingName="Avail" billingPhone="xxxx" billingPostalCode="600001" billingState="Tnadu" dateCreated="2018-05-16 11:58:22" deliveryAddress="" deliveryCity="" deliveryCountry="INR" deliveryName="" deliveryPhone="xxxxxxxxx" deliveryPostalCode="" deliveryState="" description="" gwAuthId="0000" gwReciptNo="0000" isFlagged="NO" mode="TEST" paymentId="102591103" paymentMethod="1001" paymentMode="Credit Card" processed="Yes" referenceNo="17181" status="Captured" transactionId="302443643"/>



What I have tried:

I need to Check the Transaction Status from this page How can i Check. Please Provide Sample Code. can you please help to get a output immediately thank you

解决方案

You can't "convert output to C# code" - C# is a programming language, not a database.
What you have there is what looks like a fragment of XML data - it may be possible to design a class to hold such data, but the data itself cannot be converted to code per se.


What your code is doing is making html that will cause the browser to request the url and show the result, but that's not what you want, you want your code-behind to request the url and get the result. To do that you'll need to POST to the url programatically. Look at the "HttpClient" post code in the link below

C# – Several Ways To Perform Http GET and POST Requests | Yusuf Setiawan's Blog[^]

Your dictionary of values will be things like

"TransactionID", Request.QueryString["TransId"],
// add the rest of your key\value pairs here


这篇关于如何在C#中立即获取请求和响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆