コード例 #1
0
        private static void GetAsyncWithTask()
        {
            // Stream to save the response to
            var responseSaveStream = new MemoryStream();

            // Prepare the request.
            var request = new FluentHttpRequest()
                          .BaseUrl("https://graph.facebook.com")
                          .ResourcePath("/4")
                          .Method("GET")
                          .Headers(h => h.Add("User-Agent", "FluentHttp"))
                          .QueryStrings(q => q
                                        .Add("fields", "name,first_name,last_name")
                                        .Add("format", "json"))
                          .Proxy(WebRequest.DefaultWebProxy)
                          .OnResponseHeadersReceived((o, e) => e.SaveResponseIn(responseSaveStream));

            var task = request.ExecuteTaskAsync();

            task.ContinueWith(
                t =>
            {
                var ar = t.Result;

                // seek the save stream to beginning.
                ar.Response.SaveStream.Seek(0, SeekOrigin.Begin);

                // Print the response
                Console.WriteLine("GetAsyncWithTask: ");
                Console.WriteLine(FluentHttpRequest.ToString(ar.Response.SaveStream));
            });
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: prabirshrestha/FluentHttp
        private static void GetAsyncWithTask()
        {
            // Stream to save the response to
            var responseSaveStream = new MemoryStream();

            // Prepare the request.
            var request = new FluentHttpRequest()
                .BaseUrl("https://graph.facebook.com")
                .ResourcePath("/4")
                .Method("GET")
                .Headers(h => h.Add("User-Agent", "FluentHttp"))
                .QueryStrings(q => q
                                       .Add("fields", "name,first_name,last_name")
                                       .Add("format", "json"))
                .Proxy(WebRequest.DefaultWebProxy)
                .OnResponseHeadersReceived((o, e) => e.SaveResponseIn(responseSaveStream));

            var task = request.ExecuteTaskAsync();

            task.ContinueWith(
                t =>
                {
                    var ar = t.Result;

                    // seek the save stream to beginning.
                    ar.Response.SaveStream.Seek(0, SeekOrigin.Begin);

                    // Print the response
                    Console.WriteLine("GetAsyncWithTask: ");
                    Console.WriteLine(FluentHttpRequest.ToString(ar.Response.SaveStream));
                });
        }