/// <summary> /// 初始化Http请求 /// </summary> /// <param name="httpMethod">Http动词</param> /// <param name="url">地址</param> protected HttpRequestBase(HttpMethod httpMethod, string url) { if (string.IsNullOrWhiteSpace(url)) { throw new ArgumentNullException(nameof(url)); } // System.Text.Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); _url = url; _httpMethod = httpMethod; _params = new Dictionary <string, object>(); _contentType = EnumTool.GetDescription <HttpContentType>(HttpContentType.FormUrlEncoded); _cookieContainer = new CookieContainer(); _timeout = new TimeSpan(0, 0, 30); _headers = new Dictionary <string, string>(); _encoding = System.Text.Encoding.UTF8; }
/// <summary> /// 设置内容类型 /// </summary> /// <param name="contentType">内容类型</param> public TRequest ContentType(HttpContentType contentType) { return(ContentType(EnumTool.GetDescription <HttpContentType>(contentType))); }