Decode Modulo urlencoded UTF8 in C #
-
12-10-2019 - |
Domanda
Modifica che avevo frainteso quello che stava succedendo qui .. c'è un invio POST, quindi riceverà indietro di un risultato, quindi la stringa URL che sto vedendo qui è parte della stringa di query ... quindi non mi può decodificare ciò che questo è davvero, in quanto è codificato dal popolo gateway di pagamento e non a me.
Mi piacerebbe decodificare una stringa URL
Ecco il codice:
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();
Questa è l'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>
Ecco l'URL
Problema: Come faccio a decodificare la richiesta URL = back blahblah in XML
Lo sto facendo per cercare di dimostrare ciò che è contenuto nella stringa URL (che dovrebbe essere proprio come la XML qui sopra!)
Soluzione
non ha avuto alcuna fortuna decodifica così l'URL potrebbe essere sbagliato, ma ho usato questo codice:
Uri uri = new Uri(...);
NameValueCollection query = HttpUtility.ParseQueryString(uri.Query);
string value = query["request"].Replace('-', '+').Replace('_', '/');
Debug.WriteLine(Convert.FromBase64String(value));
EDIT:. Nei loro documenti dicono è criptata ??p>
Altri suggerimenti
È possibile utilizzare una regex, qualcosa come
var match = new Regex("request=(?<key>[^&]+)").Match(url);
e catturare il valore di richiesta del gruppo denominato. Da lì, si spera si sarebbe in grado di decifrare il valore catturato.
Non ci sono garanzie che quanto sopra regex è corretta - non l'ho testato. Si dovrebbe almeno punto nella giusta direzione voi!