在 C# 中解码形式 Urlencoded UTF8

发布于 2024-10-08 17:55:58 字数 2752 浏览 3 评论 0原文

编辑我误解了这里发生的事情..有一个 POST 发送,然后收到一个结果,然后我在这里看到的 URL 字符串是查询字符串的一部分...所以我无法解码这到底是什么,因为它是由支付网关人员而不是我编码的。

我想解码 URL 字符串

这是代码:

private string SubmitXml(string InputXml)
    {
        string result = InputXml.ToString();

        HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(_WebServiceUrl);
        webReq.Method = "POST";

        byte[] reqBytes;

        reqBytes = System.Text.Encoding.UTF8.GetBytes(InputXml);
        webReq.ContentType = "application/x-www-form-urlencoded";
        webReq.ContentLength = reqBytes.Length;
        webReq.Timeout = 5000;
        Stream requestStream = webReq.GetRequestStream();
        requestStream.Write(reqBytes, 0, reqBytes.Length);
        requestStream.Close();

        HttpWebResponse webResponse = (HttpWebResponse)webReq.GetResponse();

这是 InputXml:

 - <GenerateRequest>
  <PxPayUserId>KoruCareCHCH_Dev</PxPayUserId> 
  <PxPayKey>47d99ccdcae54816ecd78c9a80f8878c466a7ed829480e59d421cc4c456cbd93</PxPayKey> 
  <AmountInput>345.00</AmountInput> 
  <BillingId /> 
  <CurrencyInput>NZD</CurrencyInput> 
  <DpsBillingId /> 
  <DpsTxnRef /> 
  <EmailAddress /> 
  <EnableAddBillCard /> 
  <MerchantReference>43</MerchantReference> 
  <TxnData1 /> 
  <TxnData2 /> 
  <TxnData3 /> 
  <TxnType>Purchase</TxnType> 
  <TxnId>43</TxnId> 
  <UrlFail>http://localhost:1527/Auction/PurchaseTickets.aspx</UrlFail> 
  <UrlSuccess>http://localhost:1527/Auction/PurchaseTickets.aspx</UrlSuccess> 
  <Opt /> 
  </GenerateRequest>

这是 URL

https://sec2. paymentexpress.com/pxpay/pxpay.aspx?userid=KoruCareCHCH_Dev&request=v5lK0D7j3qnGqQVnj3WThhuS5PoWwKhdLUXfnL1hiSzYzxzk KVtTbLKC49e0qerYoTAofoBXfkWHjJdtOEV1MrnEBZ3p9b-G5fTsS-sLqc76RhHOb8HTxtwe0EQ1kz1iCf2ExIgKRod-FPQTKf6XoTLLlQ4jhcrO7yQczrq1Hft5pB98LMJCdBX0FDNA5NV0 ZGApR0NaCMy -xbpsVSsyTbSdmp03aiHpGXI4up2RxrBFhbiEOZKtpKkjUpqJ90UuoXmFwqTC5Pj0g1mx3VRV2ee358Tnu1_kuEID_RaP8sZNTVlAMY5-8qjB-u0dgM4ya8Faxxyw5AhyE=

问题: 如何解码URL request=blahblah 回到 XML

我这样做是为了尝试证明 URL 字符串中包含的内容(它应该就像上面的 XML 一样!)

Edit I'd misunderstood what was happening here.. there is a POST send, then receive back a result, then the URL string which I'm seeing here is part of the the query string... so I can't decode what this really is, as it is encoded by the payment gateway people and not me.

I'd like to decode a URL string

Here is the code:

private string SubmitXml(string InputXml)
    {
        string result = InputXml.ToString();

        HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(_WebServiceUrl);
        webReq.Method = "POST";

        byte[] reqBytes;

        reqBytes = System.Text.Encoding.UTF8.GetBytes(InputXml);
        webReq.ContentType = "application/x-www-form-urlencoded";
        webReq.ContentLength = reqBytes.Length;
        webReq.Timeout = 5000;
        Stream requestStream = webReq.GetRequestStream();
        requestStream.Write(reqBytes, 0, reqBytes.Length);
        requestStream.Close();

        HttpWebResponse webResponse = (HttpWebResponse)webReq.GetResponse();

Here is the InputXml:

 - <GenerateRequest>
  <PxPayUserId>KoruCareCHCH_Dev</PxPayUserId> 
  <PxPayKey>47d99ccdcae54816ecd78c9a80f8878c466a7ed829480e59d421cc4c456cbd93</PxPayKey> 
  <AmountInput>345.00</AmountInput> 
  <BillingId /> 
  <CurrencyInput>NZD</CurrencyInput> 
  <DpsBillingId /> 
  <DpsTxnRef /> 
  <EmailAddress /> 
  <EnableAddBillCard /> 
  <MerchantReference>43</MerchantReference> 
  <TxnData1 /> 
  <TxnData2 /> 
  <TxnData3 /> 
  <TxnType>Purchase</TxnType> 
  <TxnId>43</TxnId> 
  <UrlFail>http://localhost:1527/Auction/PurchaseTickets.aspx</UrlFail> 
  <UrlSuccess>http://localhost:1527/Auction/PurchaseTickets.aspx</UrlSuccess> 
  <Opt /> 
  </GenerateRequest>

Here is the URL

https://sec2.paymentexpress.com/pxpay/pxpay.aspx?userid=KoruCareCHCH_Dev&request=v5lK0D7j3qnGqQVnj3WThhuS5PoWwKhdLUXfnL1hiSzYzxzkKVtTbLKC49e0qerYoTAofoBXfkWHjJdtOEV1MrnEBZ3p9b-G5fTsS-sLqc76RhHOb8HTxtwe0EQ1kz1iCf2ExIgKRod-FPQTKf6XoTLLlQ4jhcrO7yQczrq1Hft5pB98LMJCdBX0FDnA5NV0ZGApR0NaCMy-xbpsVSsyTbSdmp03aiHpGXI4up2RxrBFhbiEOZKtpKkjUpqJ90UuoXmFwqTC5Pj0g1mx3VRV2ee358Tnu1_kuEID_RaP8sZNTVlAMY5-8qjB-u0dgM4ya8Faxxyw5AhyE=

Problem: How do I decode the URL request=blahblah back into XML

I'm doing this to try and prove what is contained in the URL string (it should be just like the XML above!)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南街九尾狐 2024-10-15 17:55:58

没有任何运气对其进行解码,因此 URL 可能是错误的,但我使用了以下代码:

Uri uri = new Uri(...);
NameValueCollection query = HttpUtility.ParseQueryString(uri.Query);
string value = query["request"].Replace('-', '+').Replace('_', '/');
Debug.WriteLine(Convert.FromBase64String(value));

编辑:在他们的文档中,他们说它是加密的。

Didn't have any luck decoding it so the URL might be wrong, but I used this code:

Uri uri = new Uri(...);
NameValueCollection query = HttpUtility.ParseQueryString(uri.Query);
string value = query["request"].Replace('-', '+').Replace('_', '/');
Debug.WriteLine(Convert.FromBase64String(value));

EDIT: In their docs they say it's encrypted.

狼性发作 2024-10-15 17:55:58

您可以使用正则表达式,例如

var match = new Regex("request=(?<key>[^&]+)").Match(url);

捕获命名组中的请求值。从那里,希望您能够解密捕获的值。

不保证上述正则表达式是正确的 - 我还没有测试过。它至少应该为您指明正确的方向!

You can use a regex, something like

var match = new Regex("request=(?<key>[^&]+)").Match(url);

and capture the request value in the named group. From there, hopefully you'd be able to decrypt the captured value.

No guarantees that the above regex is correct - I haven't tested it. It should at least point you in the right direction!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文