Advertisement
Guest User

Untitled

a guest
Jun 28th, 2014
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Net.Http;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace GW2TPv2
  10. {
  11. class Class1
  12. {
  13. private HttpClient httpClient;
  14. private HttpClientHandler httpClientHandler;
  15. private CookieContainer cookieContainer;
  16. private Uri baseAddress;
  17.  
  18. public Class1()
  19. {
  20. // First we set the base address
  21. baseAddress = new Uri("http://tradingpost-dfw-live.ncplatform.net");
  22. cookieContainer = new CookieContainer();
  23. cookieContainer.Add(baseAddress, new Cookie("s", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")); //add session id
  24.  
  25. // "http://tradingpost-dfw-live.ncplatform.net"
  26. }
  27.  
  28. //I call this in my Main()
  29. public async void request()
  30. {
  31. //Something isn't right in here?
  32. httpClientHandler = new HttpClientHandler()
  33. {
  34. CookieContainer = cookieContainer,
  35. UseCookies = false
  36. };
  37.  
  38. using (httpClient = new HttpClient() { BaseAddress = baseAddress })
  39. {
  40. // More setup
  41. httpClient.MaxResponseContentBufferSize = 256000;
  42. httpClient.DefaultRequestHeaders.Add("user-agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)");
  43.  
  44.  
  45. try
  46. {
  47. string response;
  48. HttpResponseMessage httpresponse = await httpClient.GetAsync("http://tradingpost-dfw-live.ncplatform.net");
  49. httpresponse.EnsureSuccessStatusCode();
  50.  
  51. response = await httpresponse.Content.ReadAsStringAsync();
  52. Console.WriteLine(response);
  53.  
  54. }
  55. catch (HttpRequestException hre)
  56. {
  57. Console.WriteLine(hre.ToString());
  58. }
  59. catch (Exception ex)
  60. {
  61. // For debugging
  62. Console.WriteLine(ex.ToString());
  63. }
  64. }
  65.  
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement