JsonValue GetTokenFromCode(string code)
        {
            // get the access token
            // https://developers.facebook.com/docs/howtos/login/server-side-login/
            JsonValue token = null;

            using (WebRequest request = new WebRequest(
                       "https://graph.facebook.com/oauth/access_token?" +
                       "code=" + HttpUtility.UrlEncode(code) + "&" +
                       "client_id=" + HttpUtility.UrlEncode(ClientId) + "&" +
                       "client_secret=" + HttpUtility.UrlEncode(ClientSecret) + "&" +
                       "redirect_uri=" + HttpUtility.UrlEncode(RedirectUri),
                       allowAutoRedirect: true)) {
                HttpClientResponse response = request.GetResponse();
                if (response.StatusCode == 200)
                {
                    string   paramsString = response.ReadAsString();
                    string[] tab          = paramsString.Split('&');
                    token = new JsonObject();
                    for (int i = 0; i < tab.Length; i++)
                    {
                        string[] tab2 = tab[i].Split('=');
                        if (tab2.Length == 2)
                        {
                            token[tab2[0]] = tab2[1];
                        }
                    }
                }
            }
            return(token);
        }
        public static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Usage: TestHttpClient.exe [URL]");
            }
            else
            {
                Uri uri = new Uri(args[0]);
                using (HttpClient client = HttpClient.Create(uri.Host, uri.Port)) {
                    HttpClientRequest request = new HttpClientRequest();
                    request.Method = "GET";
                    request.Path   = uri.PathAndQuery;
                    client.SendRequest(request);
                    HttpClientResponse response = client.GetResponse();

                    Console.WriteLine(response.Protocol + " " + response.Status);
                    foreach (string key in response.Headers.Keys)
                    {
                        Console.WriteLine(key + ": " + response.Headers[key]);
                    }
                    Console.WriteLine();
                    Console.WriteLine(response.ReadAsString());
                }
            }
        }
Beispiel #3
0
        public static bool TestStaticFilesService()
        {
            bool done = false;

            using (HttpClient client = HttpClient.Create("localhost", 3333)) {
                HttpClientRequest request = new HttpClientRequest();
                request.Method = "GET";
                request.Path   = "/files/test.txt";
                client.SendRequest(request);
                HttpClientResponse response = client.GetResponse();
                string             res      = response.ReadAsString();
                done = (res == "Hello World !\n");
            }
            return(done);
        }