Skip to content

Instantly share code, notes, and snippets.

@prabirshrestha
Created March 28, 2011 17:26
Show Gist options
  • Save prabirshrestha/890884 to your computer and use it in GitHub Desktop.
Save prabirshrestha/890884 to your computer and use it in GitHub Desktop.
private static void Get()
{
var ms = new MemoryStream();
var request = new FluentHttpRequest()
.BaseUrl("https://graph.facebook.com")
.ResourcePath("/prabirshrestha")
.Method("GET")
.QueryStrings(qs =>
qs
.Add("fields", "id,name")
.Add("format", "json"))
.Headers(h => h.Add("User-Agent", "Fluent Http"))
.OnResponseHeadersReceived((o, e) => { e.ResponseSaveStream = ms; });
var ar = request.BeginExecute(null, null);
var response = request.EndExecute(ar);
ms.Seek(0, SeekOrigin.Begin);
Console.WriteLine(new StreamReader(ms).ReadToEnd());
}
private static void Post()
{
var ms = new MemoryStream();
var request = new FluentHttpRequest()
.BaseUrl("https://graph.facebook.com")
.ResourcePath("/me/feed")
.Method("POST")
.QueryStrings(qs =>
qs
.Add("format", "json"))
.Headers(h => h
.Add("User-Agent", "Fluent Http")
.Add("Content-Type", "application/x-www-form-urlencoded"))
.Body(body =>
body
.Append("message=hello"))
.AuthenticateUsing(new OAuth2AuthorizationRequestHeaderAuthenticator(AccessToken))
.OnResponseHeadersReceived((o, e) => e.ResponseSaveStream = ms);
var ar = request.BeginExecute(null, null);
var response = request.EndExecute(ar);
ms.Seek(0, SeekOrigin.Begin);
Console.WriteLine(new StreamReader(ms).ReadToEnd());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment