/// <summary> /// Gets all type request data. /// </summary> /// <param name="param"></param> /// <param name="postParamDict"></param> /// <returns></returns> public static string GetRequestResult(this ResponseParam param, IDictionary <string, string> postParamDict = null) { if (param == null) { throw new ArgumentNullException(nameof(param)); } var postData = string.Empty; if (postParamDict != null) { postData = CreateParameter(postParamDict); } var response = param.CreateHttpResponse(postData); var stream = response.GetResponseStream(); if (stream == null) { throw new NullReferenceException(nameof(stream)); } using (var reader = new StreamReader(stream, param.EncodeType)) { return(reader.ReadToEnd()); } }
/// <summary> /// Gets all type request string data. /// </summary> /// <param name="param"></param> /// <param name="url"></param> /// <param name="filePath"></param> /// <param name="postData"></param> /// <returns></returns> public static string GetTypeRequest(this ResponseParam param, string url, string filePath = null, string postData = null) { var response = param.CreateHttpResponse(url, filePath, postData); using (var reader = new StreamReader(response.GetResponseStream(), param.EncodeType)) return(reader.ReadToEnd()); }
/// <summary> /// Uploads the file. /// </summary> /// <param name="param"></param> /// <param name="url"></param> /// <param name="filePath"></param> /// <returns></returns> public static string UploadFile(this ResponseParam param, string url, string filePath) { var response = param.CreateHttpResponse(url, filePath); using (var reader = new StreamReader(response.GetResponseStream(), param.EncodeType)) return(reader.ReadToEnd()); }
/// <summary> /// Downloads the file. /// </summary> /// <param name="param"></param> /// <param name="url"></param> /// <param name="filePath"></param> /// <returns></returns> public static byte[] DownloadFile(this ResponseParam param, string url, string filePath = null) { var response = param.CreateHttpResponse(url, filePath); var st = response.GetResponseStream(); var results = new byte[response.ContentLength]; st.Read(results, 0, results.Length); st.Close(); return(results); }
/// <summary> /// Uploads the file. /// </summary> /// <param name="param"></param> /// <param name="filePath"></param> /// <returns></returns> public static string UploadFile(this ResponseParam param, FileSystemInfo filePath = null) { if (param == null) { throw new ArgumentNullException(nameof(param)); } var response = param.CreateHttpResponse(string.Empty, filePath); using (var reader = new StreamReader(response.GetResponseStream(), param.EncodeType)) return(reader.ReadToEnd()); }
/// <summary> /// Downloads the file. /// </summary> /// <param name="param"></param> /// <param name="filePath"></param> /// <returns></returns> public static byte[] DownloadFile(this ResponseParam param, FileSystemInfo filePath = null) { if (param == null) { throw new ArgumentNullException(nameof(param)); } var response = param.CreateHttpResponse(string.Empty, filePath); var st = response.GetResponseStream(); var results = new byte[response.ContentLength]; if (st != null) { st.Read(results, 0, results.Length); st.Close(); } return(results); }