Created
January 31, 2014 01:40
-
-
Save podhmo/8725130 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Net.Http; | |
using System.Threading.Tasks; | |
using System.Net.Http.Headers; | |
namespace CookieCheck | |
{ | |
class MainClass | |
{ | |
public static void Main (string[] args) | |
{ | |
Console.WriteLine ("Hello World!"); | |
var uri = "http://localhost:8000/a.txt"; | |
var handler = new HttpClientHandler() | |
{ | |
UseCookies = true, | |
}; | |
var cookieContainer = new System.Net.CookieContainer(); | |
var cookie = new System.Net.Cookie("guest_id", "v1%3A139109610161149543"); | |
cookieContainer.Add(new Uri("http://localhost/"), cookie); | |
handler.CookieContainer = cookieContainer; | |
var client = new HttpClient(handler); | |
client.DefaultRequestHeaders.Add("Accept", "*/*"); | |
Console.WriteLine("Accept: {0}", client.DefaultRequestHeaders.Accept); | |
// むり | |
//client.DefaultRequestHeaders.Add ("Cookie", "guest_id=v1%3A139109610161149543"); | |
var t = Task.Run (async () => { | |
using (var response = await client.GetAsync (uri).ConfigureAwait (false)) { | |
var result = await response.Content.ReadAsStringAsync (); | |
Console.WriteLine ("result: {0}", result); | |
} | |
}); | |
t.Wait (); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment