private CreateTimeoutTimer ( |
||
request | ||
리턴 | void |
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); }
public static HttpResponse Post(HttpPostRequest req, Action <HttpResponse> action) { HttpResponse response = new HttpResponse(req); try { string boundary = ""; HttpWebRequest request = Http.CreateRequest(req); if (req.Credentials != null) { request.Credentials = req.Credentials; } response.WebRequest = request; if (req.Files.Count == 0) { request.ContentType = "application/x-www-form-urlencoded"; } else { boundary = "----------------------------" + DateTime.Now.Ticks.ToString("x"); request.ContentType = "multipart/form-data; boundary=" + boundary; } if (req.Cookies.Count > 0) { request.CookieContainer = new CookieContainer(); foreach (Cookie current in req.Cookies) { request.CookieContainer.Add(request.RequestUri, current); } } request.Method = "POST"; 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.BeginGetRequestStream(delegate(IAsyncResult ar1) { try { using (Stream stream = request.EndGetRequestStream(ar1)) { if (req.Files.Count > 0) { Http.WritePostData(stream, boundary, req); } else { Http.WritePostData(stream, req); } } request.BeginGetResponse(delegate(IAsyncResult r) { Http.ProcessResponse(r, request, response, action); }, request); } catch (Exception exception2) { response.Exception = exception2; if (action != null) { action(response); } } }, request); } catch (Exception exception) { response.Exception = exception; if (action != null) { action(response); } } lock (Http.pendingRequests) { Http.pendingRequests.Add(response); } return(response); }
public static HttpResponse Post(HttpPostRequest req, Action<HttpResponse> action) { HttpResponse response = new HttpResponse(req); try { string boundary = ""; HttpWebRequest request = Http.CreateRequest(req); if (req.Credentials != null) { request.Credentials = req.Credentials; } response.WebRequest = request; if (req.Files.Count == 0) { request.ContentType = "application/x-www-form-urlencoded"; } else { boundary = "----------------------------" + DateTime.Now.Ticks.ToString("x"); request.ContentType = "multipart/form-data; boundary=" + boundary; } if (req.Cookies.Count > 0) { request.CookieContainer = new CookieContainer(); foreach (Cookie current in req.Cookies) { request.CookieContainer.Add(request.RequestUri, current); } } request.Method = "POST"; 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.BeginGetRequestStream(delegate(IAsyncResult ar1) { try { using (Stream stream = request.EndGetRequestStream(ar1)) { if (req.Files.Count > 0) { Http.WritePostData(stream, boundary, req); } else { Http.WritePostData(stream, req); } } request.BeginGetResponse(delegate(IAsyncResult r) { Http.ProcessResponse(r, request, response, action); }, request); } catch (Exception exception2) { response.Exception = exception2; if (action != null) { action(response); } } }, request); } catch (Exception exception) { response.Exception = exception; if (action != null) { action(response); } } lock (Http.pendingRequests) { Http.pendingRequests.Add(response); } return response; }
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; }