0

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

Kassem
  • 8,116
  • 17
  • 75
  • 116
  • I don't understand your question about redirect -- maybe that would make more sense if it was a question all to itself and you explained more? – Hogan Jun 10 '11 at 21:24
  • @Hogan: I mean, the redirect-url is encoded, right? If you grab it and try to go to it using your browser, it wouldn't work. So theoretically, doing that with code should not work as well, or am I mistaken here? – Kassem Jun 10 '11 at 21:27

2 Answers2

1

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

Community
  • 1
  • 1
Polity
  • 14,734
  • 2
  • 40
  • 40
  • Why would someone not use `Request.QueryString`? – Hogan Jun 10 '11 at 21:23
  • See my comment on your answer ;) – Polity Jun 10 '11 at 21:25
  • Not sure what the webclient is... the browser? It sounds like you are talking about something specific to the google product... but still, this is code running on the server. – Hogan Jun 10 '11 at 21:27
  • @Hogan: No, the WebClient is a .NET class that allows you to do HTTP POST calls. – Kassem Jun 10 '11 at 21:29
  • Not sure either although it sounds like a.... webClient class, long story short is that its a client, not a server (the name implies that) – Polity Jun 10 '11 at 21:29
  • @Polity: Your answer is exactly what I was looking for. It actually solved both problems posted in my question. +1 and thanks a lot :) – Kassem Jun 10 '11 at 21:34
1

There already is a name value collection in Request.QueryString.

http://msdn.microsoft.com/en-us/library/system.web.httprequest.querystring.aspx

Hogan
  • 69,564
  • 10
  • 76
  • 117