Dr.Denis McCracleJizz
Dr.Denis McCracleJizz

Reputation: 870

Using google's api to list result of search

Hey i want to list the results from a google search, i saw that you can query google's api by using urls like this one

http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=Earth%Day

In the asp.net framework i have no idea how to query this url without exiting the page. I know Response.Redirect(myquery); would work but it makes the browser leave the current page, how do i get the JSON result from that query without leaving the page ?

Thanks !

ps: I did do alot of searches before asking.

Upvotes: 1

Views: 729

Answers (1)

Alex
Alex

Reputation: 35409

Use the HttpWebRequest and HttpWebResponse classes in the .Net Framework:

var request  = (HttpWebRequest)WebRequest.Create("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=Earth%Day");

var response = (HttpWebResponse)request.GetResponse();

var responseText = (new StreamReader(response.GetResponseStream())).ReadToEnd();

http://msdn.microsoft.com/en-us/library/debx8sh9.aspx

Upvotes: 2

Related Questions