상속: IHttpRequest
예제 #1
0
파일: Http.cs 프로젝트: 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;
 }
예제 #2
0
파일: Http.cs 프로젝트: 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;
 }
예제 #3
0
파일: Http.cs 프로젝트: 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;
 }