private static string _SendPostRequest(string url, string query, HttpRequestOptions opt, out HttpResponseInfo info) { Debug.Assert(url != null); Debug.Assert(query != null); Debug.Assert(opt != null); byte[] data = Encoding.UTF8.GetBytes(query); HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; req.ContentLength = data.Length; _SetRequestOptions(req, opt); string result = null; Stream reqStream = req.GetRequestStream(); try { reqStream.Write(data, 0, data.Length); reqStream.Close(); reqStream = null; result = _GetResponse(req, out info); } finally { if (reqStream != null) { reqStream.Close(); } } return(result); }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// private static string _SendRequest(string url, string query, HttpRequestOptions opt, out HttpResponseInfo info) { Debug.Assert(url != null); Debug.Assert(query != null); Debug.Assert(opt != null); var req = (HttpWebRequest)WebRequest.Create(_BuildUrl(url, query)); _SetRequestOptions(req, opt); return _GetResponse(req, out info); }
private static string _SendPostRequest(string url, string query, HttpRequestOptions opt, out HttpResponseInfo info) { Debug.Assert(url != null); Debug.Assert(query != null); Debug.Assert(opt != null); byte[] data = Encoding.UTF8.GetBytes(query); HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; req.ContentLength = data.Length; _SetRequestOptions(req, opt); string result = null; Stream reqStream = req.GetRequestStream(); try { reqStream.Write(data, 0, data.Length); reqStream.Close(); reqStream = null; result = _GetResponse(req, out info); } finally { if (reqStream != null) reqStream.Close(); } return result; }
/// <summary> /// Gets response for the specified HTTP request. /// </summary> /// <param name="request">Request instance to get response for.</param> /// <param name="info">Response info to filled with HTTP response data.</param> /// <returns>Data contained in the HTTP response.</returns> private static string _GetResponse( HttpWebRequest request, out HttpResponseInfo info) { string result = null; using (var response = request.GetResponse()) { result = _ReadData(response); var httpResponse = (HttpWebResponse)response; info = new HttpResponseInfo { ResponseUri = httpResponse.ResponseUri, Cookies = httpResponse.Cookies, }; } return result; }
public static string SendRequest(string url, string query, HttpRequestOptions opt, out HttpResponseInfo info) { Debug.Assert(opt != null); string result = null; while (true) { try { if (opt.Method == HttpMethod.Post) result = _SendPostRequest(url, query, opt, out info); else result = _SendRequest(url, query, opt, out info); break; } catch (Exception e) { if (!ProxyAuthenticationErrorHandler.HandleError(e)) { throw; } } } return result; }