在WP8.1中下载.JSON文件

时间:2015-05-26 16:35:07

标签: c# json download windows-phone-8.1 httpwebrequest

目前,我有这段代码:

module mux418bit(a,b,c,d,s0,s1,e);
  input[7:0]a,b,c,d;
  input s0,s1;
  output [7:0]e;

  assign e = ({s0,s1} == 2'b00) ? a : 
             ({s0,s1} == 2'b01) ? b :
             ({s0,s1} == 2'b10) ? c : d;
endmodule

但Visual Studio告诉我GetResponse(第二行)并不存在。问题是什么? :/

2 个答案:

答案 0 :(得分:1)

看看HttpClient。这在WP8.1上完美运行。

using (HttpClient client = new HttpClient())
{
    using (HttpResponseMessage response = await client.GetAsync(uri, cancel))
    {
        using (Stream stream = response.Content.ReadAsStreamAsync().Result)
        {
            using (StreamReader reader = new StreamReader(stream))
            {
                return new JsonSerializer().Deserialize<T>(new JsonTextReader(reader));
            }
        }
    }
}

答案 1 :(得分:1)

问题在于&#34; Microsoft HTTP客户端库&#34; Nuget包版本的程序集不支持该方法。相反,您仅限于以下内容,这基本上意味着您必须使用BeginGetRequestStream和其他异步方法: https://msdn.microsoft.com/en-us/library/system.net.httpwebrequest(v=vs.95).aspx

以下是如何发出请求的示例(上下文是Silverlight文章,但它适用于您的情况): http://www.c-sharpcorner.com/uploadfile/mgold/implementing-the-http-requestresponse-model-inside-of-silverlight/