Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过WebClient请求JSON返回URL会引发异常_C#_Json_Asp.net Mvc 3_Facebook Graph Api_Webclient - Fatal编程技术网

C# 通过WebClient请求JSON返回URL会引发异常

C# 通过WebClient请求JSON返回URL会引发异常,c#,json,asp.net-mvc-3,facebook-graph-api,webclient,C#,Json,Asp.net Mvc 3,Facebook Graph Api,Webclient,我正在使用WebClient向Facebook Graph API发送一个请求,其中包含在ASP.net MVC控制器类中编写的以下代码: WebClient client2 = new WebClient(); Stream data2 = client2.OpenRead("https://graph.facebook.com/me&" + s); StreamReader reader2 = new StreamReader(data); //E

我正在使用WebClient向Facebook Graph API发送一个请求,其中包含在ASP.net MVC控制器类中编写的以下代码:

 WebClient client2 = new WebClient();

        Stream data2 = client2.OpenRead("https://graph.facebook.com/me&" + s);
        StreamReader reader2 = new StreamReader(data); //Error


        string s2 = reader2.ReadToEnd();
        data2.Close();
        reader2.Close();

        s2=s2.Substring(s2.IndexOf('"', s2.IndexOf(':')), s2.Length - s2.IndexOf('"', s2.IndexOf(':')));

        s2= s2.Substring(1, s2.IndexOf('"', 1) - 1);

        return "AccessToken Stored in session, Current Signed in user is: "+s2;

我得到了这个错误:“System.ArgumentException:流不可读。”行中注释为//错误。此请求返回JSON格式的数据。这是导致此异常的原因吗?请帮忙。如何解决此问题?

我可能会指出显而易见的问题,但您正在创建“data2”变量之后立即将“data”变量传递到StreamReader构造函数中。我猜你是想用“数据2”来代替吗?

哦,我犯了一个愚蠢的错误。谢谢你指出。这正是问题所在$别担心。我肯定也犯了同样的错误。