日期:2014-05-17  浏览次数:20526 次

新浪API获取评论列表时出现问题,求助
  public static string GetResult(string url)
        {
            string username = "账户";
            string password = "密码";
            string usernamePassword = username + ":" + password;
            WebRequest webRequest = WebRequest.Create(url);
            HttpWebRequest myReq = webRequest as HttpWebRequest;
            CredentialCache myCache = new CredentialCache();
            myCache.Add(new Uri(url), "Basic", new NetworkCredential(username, password));
            myReq.Credentials = myCache;
            myReq.Headers.Add("Authorization", "Basic " +
            Convert.ToBase64String(new System.Text.ASCIIEncoding().GetBytes(usernamePassword)));
            WebResponse wr = myReq.GetResponse();
            Stream receiveStream = wr.GetResponseStream();
            StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8);
            return reader.ReadToEnd();
        }

        public static string GetResult(string url)
        {
            WebClient client = new WebClient();
            client.Encoding = Encoding.UTF8;
            string str = string.Empty;
            try
            {
                str = client.DownloadString(url);
            }
            catch
            {
                throw;
            }
            finally
            {
                client.Dispose();
            }
            return str;