1

Facebookの連絡先を取得するためのWindows8Metroアプリを作成しています。Windows 7で作成された通常のWindowsアプリケーションではWebClient、を受け入れます。

private WebClient wc = new WebClient();
string jsonResponse = wc.DownloadString("https://graph.facebook.com/" + ID);
FacebookUser User = JsonConvert.DeserializeObject<FacebookUser>(jsonResponse);

しかし、これは私のWindows8Metroアプリでは機能しません

だから、私は使い始めましHTTPRequestHTTPResponse

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";

応答(Facebookの連絡先のリスト)をJSONとして取得する方法がわかりません。

誰か助けてくれませんか?

4

2 に答える 2

2

ありがとう、私はメソッドを作成しました、

    public async void PerformHttpGet(string url,out string responseText)
    {
        int respCode = 0;
        try
        {
            // used to build entire input
            StringBuilder sb = new StringBuilder();

            // used on each read operation
            byte[] buf = new byte[8192];

            // prepare the web page we will be asking for
            HttpClient searchClient;
            searchClient = new HttpClient();
            searchClient.MaxResponseContentBufferSize = 256000;
            HttpResponseMessage response = await searchClient.GetAsync(url);
            response.EnsureSuccessStatusCode();
            responseText = await response.Content.ReadAsStringAsync();
        }
        catch (WebException e)
        {
            string text = string.Empty;
            string outRespType = string.Empty;
            if (e.Response != null)
            {
                using (WebResponse response = e.Response)
                {
                    outRespType = response.ContentType;
                    HttpWebResponse exceptionResponse = (HttpWebResponse)response;
                    respCode = (int)exceptionResponse.StatusCode;

                    using (System.IO.Stream data = response.GetResponseStream())
                    {
                        text = new System.IO.StreamReader(data).ReadToEnd();
                    };
                };
            }
            throw e;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }      
于 2012-11-01T08:40:54.927 に答える
1

使用System.Net.Http.HttpClient:

HttpClient client = new HttpClient();
client.MaxResponseContentBufferSize = 256000;
HttpResponseMessage response = await client.GetAsync(address);
response.EnsureSuccessStatusCode();
String jsonResponse = await response.Content.ReadAsStringAsync();
FacebookUser User = JsonConvert.DeserializeObject<FacebookUser>(jsonResponse);
于 2012-11-01T07:15:19.727 に答える