首页 > 解决方案 > 获取json数据时无法连接到远程服务器Windows 8.1 App

问题描述

我尝试使用以下方法从 Windows 8.1 应用程序获取一些 json 数据:

  public async Task<string> Get(string Url)
    {
        try
        {
            var request = (HttpWebRequest)WebRequest.Create(Url);
            HttpWebResponse response = await request.GetResponseAsync() as HttpWebResponse;
            Stream responseStream = response.GetResponseStream();
            using (StreamReader sr = new StreamReader(responseStream))
            {

                //Need to return this response 
                string strContent = sr.ReadToEnd();
                return strContent;
            }

        }
        catch (Exception e)
        {
            throw e;
        }
    }

我得到了这个异常:连接尝试失败,因为连接的一方在一段时间后没有正确响应,或者建立连接失败,因为连接的主机没有响应 ServerIP:80

尽管我在 Windows 10 UMP App 上使用了相同的代码,但没有错误,我得到了我的数据。

请问Windows 8.1 应用有什么问题?

标签: c#jsonweb-serviceswindows-store-apps

解决方案


推荐阅读