Monday, 26 August 2013

Build a Json Request Url Using C#

Build a Json Request Url Using C#

I've been trying to build the request url for my json request but been
getting a 404 error. This is the code I put together after reading some
threads on it. Can anyone help?
var apiKey = "123456";
var Query = "some search";
var Location = "San Jose, CA";
var Sort = "1";
var SearchRadius = "100";
var values = HttpUtility.ParseQueryString(string.Empty);
values["k"] = apiKey;
values["q"] = Query;
values["l"] = Location;
values["sort"] = Sort;
values["radius"] = SearchRadius;
string url = "http://api.website.com/api" + values.toString();
This is where I am getting the error. After passing the url on
client.DownloadString()
var client = new WebClient();
var json = client.DownloadString(url);
var search = Json.Decode(json);

No comments:

Post a Comment