public IHttpActionResult Get() { try { string appPath = HostingEnvironment.ApplicationPhysicalPath; string filePath = Path.Combine(appPath, @"Data\\en-chs-dictionary.txt"); string dicText = File.ReadAllText(filePath, Encoding.Default); Misc misc = new Misc(); string errorInfo = string.Empty; string updateTime = misc.Get("dictionary_update_time", ref errorInfo); if (string .IsNullOrEmpty(updateTime)) { if (errorInfo == "Not exist") return NotFound(); return BadRequest(errorInfo); } return Ok(new { UpdateTime = updateTime, Content = dicText }); } catch (Exception ex) { _log.Error(ex.ToString()); return BadRequest(ex.ToString()); } }
public HttpResponseMessage Head() { try { HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, "value"); Misc misc = new Misc(); string errorInfo = string.Empty; string updateTime = misc.Get("dictionary_update_time", ref errorInfo); if (string.IsNullOrEmpty(updateTime)) { if (errorInfo == "Not exist") return Request.CreateResponse(HttpStatusCode.NotFound, ""); return Request.CreateResponse(HttpStatusCode.BadRequest, errorInfo); } HttpResponseMessage resp = Request.CreateResponse(HttpStatusCode.OK, ""); resp.Headers.Add("dictionary_update_time", updateTime); return resp; } catch (Exception ex) { _log.Error(ex.ToString()); return Request.CreateResponse(HttpStatusCode.BadRequest, ex.ToString()); } }