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

问题描述

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



responseStream.Length附近获得一个问题

responseStream.Position as



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.Position as

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

推荐答案

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()中出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 21:53