Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Below is my code. I'm trying to get image results from google for my given key words.
Getting an issue near
responseStream.Length as 'responseStream.Length' threw an exception of type 'System.NotSupportedException'
responseStream.Position as 'responseStream.Position' threw an exception of type 'System.NotSupportedException'

C#
string requestUri = string.Format("http://images.google.com/images?q={0}&ndsp={1}&start={2}&filter={3}&safe={4}",query, RESULTS_PER_QUERY.ToString(),(startPosition + i).ToString(), (filterSimilarResults) ? "1" : "0", safeSearchStr);

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUri);
                string resultPage = string.Empty;
                using (HttpWebResponse httpWebResponse = (HttpWebResponse)request.GetResponse())
                {
                    using (Stream responseStream = httpWebResponse.GetResponseStream())
                    {
                        using (StreamReader reader = new StreamReader(responseStream))
                        {
                            resultPage = reader.ReadToEnd();
                        }
                    }
                }
Posted
Updated 15-Nov-14 19:50pm
v2
Comments
DamithSL 16-Nov-14 1:57am    
what is the value of requestUri? have you try that on browser url?
sumanth n 16-Nov-14 2:07am    
Yes i tried.I'm getting right results for my key words

1 solution

I think you are referring some old resource for fetching images using google image search, time to time google search parameters are changing. I have done below simple test with minimum parameters and able to receive page content.
C#
string url = string.Format("https://www.google.com/search?site=imghp&tbm=isch&q={0}", "codeproject");
HttpWebRequest request =
(HttpWebRequest)WebRequest.Create(url);
string resultPage = string.Empty;
using (HttpWebResponse httpWebResponse =
            (HttpWebResponse)request.GetResponse())
{
    using (Stream responseStream =
                httpWebResponse.GetResponseStream())
    {
        using (StreamReader reader =
                    new StreamReader(responseStream))
        {
            resultPage = reader.ReadToEnd();
        }
    }
} 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900