Reputation: 6626
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
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!)
Upvotes: 0
Views: 5426
Reputation: 6059
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!
Upvotes: 0
Reputation: 2134
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.
Upvotes: 2