Search code examples
c#.netasp.net-mvc-3stringgoogle-checkout

Convert byte array into a Dictionary or NameValueCollection?


I have the following line in my code which clearly returns a byte array:

byte[] responseArray = myWebClient.UploadValues(uriString, data);

When I do myWebClient.Encoding.GetString(responseArray) I get the following:

_type=checkout-redirect&redirect-url=https%3A%2F%2Fsandbox.google.com%2Fcheckout%2Fview%2Fbuy%3Fo%3Dshoppingcart%26shoppingcart%3D608260789399787

So as you can see, this is a perfect candidate for converting to something that has a key and a value. So my question: is there any C# function to do that for me or do I have to parse the string myself and do it all manually?

Also, what about the redirect-url, I do not think I could redirect users to it the way it is, so I guess I have to decode it? Any suggestions on how to do that?

Thanks in advance


Solution

  • As said here: How to parse a query string into a NameValueCollection in .NET

    There's a built-in .NET utility for this: HttpUtility.ParseQueryString