public static bool Get(string baseUrl, System.Collections.Generic.Dictionary <string, string> dictParam, out string result, out string errMsg, bool isurlencode = true, bool islog = true) { errMsg = string.Empty; result = string.Empty; bool result3; try { using (HttpClient httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); string lastUrl = WebApiHepler.GetLastUrl(baseUrl, dictParam, isurlencode); HttpResponseMessage result2 = httpClient.GetAsync(lastUrl).Result; result2.EnsureSuccessStatusCode(); result = result2.Content.ReadAsStringAsync().Result; if (islog) { NetLog.WriteError("Send:" + lastUrl + ";back:" + result); } result3 = true; } } catch (System.Exception ex) { errMsg = ex.Message; result3 = false; } return(result3); }
public static void WriteError(string errorMessage) { try { string path = "~/Log/" + System.DateTime.Today.ToString("yyMMdd") + ".txt"; if (!System.IO.File.Exists(HttpContext.Current.Server.MapPath(path))) { System.IO.File.Create(HttpContext.Current.Server.MapPath(path)).Close(); } using (System.IO.StreamWriter streamWriter = System.IO.File.AppendText(HttpContext.Current.Server.MapPath(path))) { streamWriter.WriteLine("\r\nLog Entry : "); streamWriter.WriteLine("{0}", System.DateTime.Now.ToString(System.Globalization.CultureInfo.InvariantCulture)); streamWriter.WriteLine(errorMessage); streamWriter.WriteLine("________________________________________________________"); streamWriter.Flush(); streamWriter.Close(); } } catch (System.Exception ex) { NetLog.WriteError(ex.Message); } }