Inheritance: IHttpRequest
Ejemplo n.º 1
0
Archivo: Http.cs Proyecto: liquidboy/X
 public static Task<HttpResponse> GetAsync(HttpGetRequest request)
 {
     TaskCompletionSource<HttpResponse> task = new TaskCompletionSource<HttpResponse>();
     Http.Get(request, delegate(HttpResponse result)
     {
         if (result.Successful)
         {
             task.SetResult(result);
             return;
         }
         if (result.Canceled)
         {
             task.SetCanceled();
             return;
         }
         task.SetException(result.Exception);
     });
     return task.Task;
 }
Ejemplo n.º 2
0
Archivo: Http.cs Proyecto: liquidboy/X
 private static HttpWebRequest CreateRequest(HttpGetRequest req)
 {
     string queryString = Http.GetQueryString(req.Query);
     HttpWebRequest result;
     if (string.IsNullOrEmpty(queryString))
     {
         result = (HttpWebRequest)WebRequest.Create(req.Uri.AbsoluteUri);
     }
     else
     {
         if (req.Uri.AbsoluteUri.Contains("?"))
         {
             result = (HttpWebRequest)WebRequest.Create(req.Uri.AbsoluteUri + "&" + queryString);
         }
         else
         {
             result = (HttpWebRequest)WebRequest.Create(req.Uri.AbsoluteUri + "?" + queryString);
         }
     }
     return result;
 }
Ejemplo n.º 3
0
Archivo: Http.cs Proyecto: liquidboy/X
 public static HttpResponse Get(HttpGetRequest req, Action<HttpResponse> action)
 {
     HttpResponse response = new HttpResponse(req);
     try
     {
         if (!req.UseCache)
         {
             req.Query["__dcachetime"] = DateTime.Now.Ticks.ToString();
         }
         HttpWebRequest request = Http.CreateRequest(req);
         if (req.Credentials != null)
         {
             request.Credentials = req.Credentials;
         }
         response.WebRequest = request;
         if (req.Cookies.Count > 0)
         {
             request.CookieContainer = new CookieContainer();
             foreach (Cookie current in req.Cookies)
             {
                 request.CookieContainer.Add(request.RequestUri, current);
             }
         }
         request.Method = "GET";
         if (req.ContentType != null)
         {
             request.ContentType = req.ContentType;
         }
         if (req.Header.Count > 0)
         {
             foreach (KeyValuePair<string, string> current2 in req.Header)
             {
                 request.Headers[current2.Key] = current2.Value;
             }
         }
         response.CreateTimeoutTimer(request);
         request.BeginGetResponse(delegate(IAsyncResult r)
         {
             Http.ProcessResponse(r, request, response, action);
         }, request);
     }
     catch (Exception exception)
     {
         response.Exception = exception;
         if (action != null)
         {
             action(response);
         }
     }
     lock (Http.pendingRequests)
     {
         Http.pendingRequests.Add(response);
     }
     return response;
 }