从Google Image获取结果时,在GetResponseStream()中出现问题 [英] Issue in GetResponseStream() when getting results from Google Image

查看:421
本文介绍了从Google Image获取结果时,在GetResponseStream()中出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的代码。我正在尝试从谷歌获取我给定关键词的图像结果。



responseStream.Length附近获得一个问题'responseStream.Length'扔了一个类型'System.NotSupportedException'的异常

responseStream.Position as 'responseStream.Position'引发类型'System.NotSupportedException'的异常



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'

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();
                        }
                    }
                }

推荐答案

我认为你是指一些旧资源来获取图像使用谷歌图片搜索,谷歌搜索参数不断变化。我用以下参数进行了简单测试,并且能够接收页面内容。

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.
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();
        }
    }
} 


这篇关于从Google Image获取结果时,在GetResponseStream()中出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆