1

I have a URL which basically looks like this:

https://example.com/us/cgi-bin/webscr?cmd=_express-checkout\u0026token=EC-2BF46053LU471230V

The URL is generated from a statement like following:

if ((int)response.StatusCode == 200 || (int)response.StatusCode == 201)
  {
      var res = await content.ReadAsStringAsync();
      var url = HttpUtility.HtmlDecode(JsonConvert.DeserializeObject<PayPalBlueReference>(res).paypalTransaction.paypalUrl);

      return Json(Regex.Unescape(url), JsonRequestBehavior.AllowGet);
  }

For some reason my URL contains the:

\u0026

Sign which I'm not able to get rid of even after using

Regex.Unescape()

Method... I have even tried using the

Replace("\u0026","&") 

but that didn't work either...

The URL should be formatted like this:

https://example.com/us/cgi-bin/webscr?cmd=_express-checkout&token=EC-2BF46053LU471230V

Can someone help me out ?

Edit: the returned JSON from server looks like this:

"https://example.com/us/cgi-bin/webscr?cmd=_express-checkout\u0026token=EC-2BF46053LU471230V"

Edit2: This is using rokkerboci's method:

   if ((int)response.StatusCode == 200 || (int)response.StatusCode == 201)
        {
            var res = await content.ReadAsStringAsync();
            var url = HttpUtility.HtmlDecode(JsonConvert.DeserializeObject<PayPalBlueReference>(res).paypalTransaction.paypalUrl);

            return Json(url.Replace("\\u0026", "&"), JsonRequestBehavior.AllowGet);
        }

The response still contains \u0026

User987
  • 3,663
  • 15
  • 54
  • 115

1 Answers1

1

You can do it using the System.Web namespace:

string encoded = "https://example.com/us/cgi-bin/webscr?cmd=_express-checkout\u0026token=EC-2BF46053LU471230V";

var unencoded = HttpUtility.HtmlDecode(encoded);

Console.WriteLine(unencoded);
rokkerboci
  • 1,167
  • 1
  • 7
  • 14
  • the original URL doesn't looks like this... Wait I'll post the original URL which is shown before the Html.Decode – User987 Jan 15 '18 at 17:55
  • "https\u0026#x3a;\u0026#x2f;\u0026#x2f;www.example.com\u0026#x2f;us\u0026#x2f;cgi-bin\u0026#x2f;webscr\u0026#x3f;cmd\u0026#x3d;_express-checkout\u0026#x26;token\u0026#x3d;EC-7M752271TC172121Y" – User987 Jan 15 '18 at 17:56
  • for some reason it doesn't :( ... U can see it in my code that I'm using HTMLDecode.. I mean its just 2 lines of code, what could I've done wrong ? xD – User987 Jan 15 '18 at 17:57
  • I dont't recognize this part: \u0026#x3a; what is the #x3a? – rokkerboci Jan 15 '18 at 17:58
  • I have no clue honestly =/ – User987 Jan 15 '18 at 18:00
  • The weird part is that URL gets pretty nicely decoded when I use the Decode but I can't seem to be able to get rid of this \u0026 – User987 Jan 15 '18 at 18:01