public static byte[] Create(HttpCode httpCode, string content, bool closeConnection = false) { var sb = new StringBuilder(); using (var sw = new StringWriter(sb)) { sw.WriteLine($"HTTP/1.1 {(int)httpCode} {httpCode}"); sw.WriteLine($"Date: {DateTime.Now.ToUniversalTime():r}"); sw.WriteLine("Server: Arctium-Emulation"); sw.WriteLine("Retry-After: 600"); sw.WriteLine($"Content-Length: {content.Length}"); sw.WriteLine("Vary: Accept-Encoding"); if (closeConnection) sw.WriteLine("Connection: close"); sw.WriteLine("Content-Type: application/json;charset=UTF-8"); sw.WriteLine(); sw.WriteLine(content); } return Encoding.UTF8.GetBytes(sb.ToString()); }
/// <summary> /// /// </summary> /// <param name="Code"></param> /// <param name="CodeString"></param> public void SetHttpCode(HttpCode Code, string CodeString = null) { if (CodeString == null) CodeString = HttpCodeUtils.GetStringFromId((HttpCode)Code); this.HttpCodeNumber = (int)Code; this.HttpCodeString = CodeString; }
public FileResponse(HttpCode aStatus, string aMime, FileInfo aBody) { status = aStatus; body = aBody; headers["Content-Type"] = aMime; headers["Content-Length"] = body.Length.ToString(); }
public StringResponse(HttpCode aStatus, string aMime, string aBody) { status = aStatus; body = aBody; headers["Content-Type"] = aMime; headers["Content-Length"] = Encoding.UTF8.GetByteCount(body).ToString(); }
public ResourceResponse(HttpCode aStatus, string type, ResourceManager aResourceManager, string aResource) { status = aStatus; try { resource = aResourceManager.GetObject(aResource) as byte[]; headers["Content-Type"] = type; headers["Content-Length"] = resource.Length.ToString(); } catch (Exception ex) { Error("Failed to prepare resource " + aResource, ex); throw; } }
public void HttpCode_Contains_Valid_Value(HttpCode httpCode, int expectedHttpCode) { Assert.That((int)httpCode, Is.EqualTo(expectedHttpCode)); }
public HttpStatusException(HttpCode code, Exception innerException) : base(HttpPhrases.Phrases[code], innerException) { Code = code; }
public FileResponse(HttpCode aStatus, FileInfo aBody) : this(aStatus, "text/html; charset=utf-8", aBody) { }
public HttpException(HttpCode HttpCode) { this.HttpCode = HttpCode; }
private void DownloadState() { try { // Command FileComponent file = Owner.Get <FileComponent>(); DownloadRequestCommand command = new DownloadRequestCommand(Entity, Connection); HttpCode code = command.Execute(Id, file, ClientId); if (code == HttpCode.Ok) { byte[] data = command.Data; if (data != null) { // Data JsonChunk jsonChunk = command.Chunk; Debug.Assert(data.Length == jsonChunk.Size); while (true) { try { FileUtil.Write(file.Path, data, jsonChunk.Offset); break; } catch (IOException ex) { Console.WriteLine(ex.Message); Status = DemonStatus.Warning; Thread.Sleep(DemonTimeout.File); } } TransferComponent transfer = Owner.Get <TransferComponent>(); transfer.Size += jsonChunk.Size; if (transfer.Done) { State = DemonState.Shutdown; Status = DemonStatus.Success; } } else { if (Id == null) { FileUtil.Create(file.Path, file.Size); if (code == HttpCode.Ok) { // Data Id = command.Id; if (!Paused && !Cancelled) { Status = DemonStatus.Success; } } } else { // TODO: Implement infinite time-out? // Sleep(DemonTimeout.Seconds); } } } else { State = DemonState.Shutdown; } } catch (Exception ex) { Console.WriteLine(ex.Message); State = DemonState.Shutdown; Status = DemonStatus.Error; } }
public HttpStatusException(string message, Exception innerException) : base(message, innerException) { Code = HttpCode.None; }
public HttpStatusException(string message) : base(message) { Code = HttpCode.None; }
public HttpStatusException(HttpCode code) : base(HttpPhrases.Phrases[code]) { Code = code; }
public static byte[] Create(HttpCode httpCode, HttpHeader header) { StringBuilder stringBuilder = HttpResponse.smethod_0(); StringWriter stringWriter = HttpResponse.smethod_1(stringBuilder); try { HttpResponse.smethod_3(stringWriter, HttpResponse.smethod_2(Module.smethod_34 <string>(793455672u), (int)httpCode, httpCode.ToString())); while (true) { IL_14D: uint arg_128_0 = 3463570091u; while (true) { uint num; switch ((num = (arg_128_0 ^ 3407657466u)) % 6u) { case 0u: goto IL_14D; case 1u: { string arg = DateTime.Now.ToUniversalTime().ToString(Module.smethod_35 <string>(3442331584u)); stringWriter.WriteLine(string.Format(Module.smethod_33 <string>(2252403819u), arg)); arg_128_0 = (num * 3193603854u ^ 2500099970u); continue; } case 3u: stringWriter.WriteLine(); stringWriter.WriteLine(header.Content); arg_128_0 = (num * 2561694936u ^ 3069112476u); continue; case 4u: stringWriter.WriteLine(Module.smethod_34 <string>(1984368261u)); stringWriter.WriteLine(Module.smethod_34 <string>(672055693u)); arg_128_0 = (num * 3931759688u ^ 2273372317u); continue; case 5u: stringWriter.WriteLine(string.Format(Module.smethod_37 <string>(609665147u), header.ContentLength)); stringWriter.WriteLine(Module.smethod_35 <string>(3987891873u)); stringWriter.WriteLine(Module.smethod_34 <string>(3147617483u)); arg_128_0 = (num * 2465592752u ^ 1798369301u); continue; } goto Block_3; } } Block_3 :; } finally { if (stringWriter != null) { while (true) { IL_18D : uint arg_174_0 = 2977987066u; while (true) { uint num; switch ((num = (arg_174_0 ^ 3407657466u)) % 3u) { case 0u: goto IL_18D; case 2u: ((IDisposable)stringWriter).Dispose(); arg_174_0 = (num * 200705565u ^ 3116199384u); continue; } goto Block_6; } } Block_6 :; } } return(Encoding.UTF8.GetBytes(stringBuilder.ToString())); }
public ActionResult EntryRecord() { int uid = Convert.ToInt32(Request.QueryString["uid"]); int aid = Convert.ToInt32(Request.QueryString["afficheID"]); string afficheID = aid.ToString(); EntryRecordInfo Model = new EntryRecordInfo(); int clientPlatform = 4; viewLite viewLite = new viewLite { frameName = "EcrpMain", viewName = "AfficheTable" }; Dictionary <string, object> parameters = new Dictionary <string, object>(); parameters.Add("clientPlatform", clientPlatform); parameters.Add("viewLite", viewLite); parameters.Add("id", aid); string jsonStr = ToJson.ScriptSerialize(parameters); string url = "Http://61.155.203.29:60214/service.svc/ReadDataById2"; string resultStr = HttpCode.Post(url, jsonStr); Dictionary <string, object> obj = JsonTo.ScriptDeserialize(resultStr); string value = obj["value"].ToString(); Dictionary <string, object> s = JsonTo.ScriptDeserialize(value); object a = s["values"]; Dictionary <string, object> values = a as Dictionary <string, object>; int a_uid = Convert.ToInt32(s["uid"]); if (a_uid == uid) { Model.issuccess = 1; Model.eventname = values["x.title"].ToString(); viewLite viewLite2 = new viewLite { frameName = "EcrpMain", viewName = "SignTable" }; sortInfo sortInfo = new sortInfo { sortType = 6 }; ConditionInfo ConditionInfo_affichelID = new ConditionInfo { columnName = "afficheID", conditionKind = 0, columnValue = afficheID }; List <ConditionInfo> conditions = new List <ConditionInfo>(); conditions.Add(ConditionInfo_affichelID); searchInfo searchInfo = new searchInfo { allowDrop = false, pageCount = -1, sortInfo = sortInfo, conditions = conditions };; Dictionary <string, object> parameters2 = new Dictionary <string, object>(); parameters2.Add("clientPlatform", clientPlatform); parameters2.Add("viewLite", viewLite2); parameters2.Add("searchInfo", searchInfo); string jsonStr2 = ToJson.ScriptSerialize(parameters2); string url2 = "Http://61.155.203.29:60214/service.svc/ReadDatasBySearchInfo2"; string resultStr2 = HttpCode.Post(url2, jsonStr2); Dictionary <string, object> obj2 = JsonTo.ScriptDeserialize(resultStr2); object objvalue = obj2["value"]; if (objvalue == null) { Model.list = null; Model.count = 0; } else { string value2 = obj2["value"].ToString(); List <Dictionary <string, object> > val = JsonTo.ScriptDeserializeList(value2); Model.list = val; Model.count = val.Count(); } } else { Model.issuccess = 0; } return(View(Model)); }
internal Redirect(HttpCode code, Uri uri) : this(code, uri.AbsoluteUri) { }
// // GET: /Home/ public ActionResult Index() { DataInfo Model = new DataInfo(); int clientPlatform = 4; //viewLite viewLite = new viewLite { frameName = "EcrpSole", viewName = "ProfileTable" }; viewLite viewLite = new viewLite { frameName = "EcrpMain", viewName = "AfficheTable" }; sortInfo sortInfo = new sortInfo { sortType = 6 }; searchInfo searchInfo = new searchInfo { allowDrop = false, pageCount = 20, pageIndex = 1, sortInfo = sortInfo };; Dictionary <string, object> parameters = new Dictionary <string, object>(); parameters.Add("clientPlatform", clientPlatform); parameters.Add("viewLite", viewLite); parameters.Add("searchInfo", searchInfo); string jsonStr = ToJson.ScriptSerialize(parameters); string url = "Http://61.155.203.29:60214/service.svc/ReadDatasBySearchInfo2"; string resultStr = HttpCode.Post(url, jsonStr); Dictionary <string, object> obj = JsonTo.ScriptDeserialize(resultStr); string value = obj["value"].ToString(); List <Dictionary <string, object> > val = JsonTo.ScriptDeserializeList(value); //Model.count = val.Count; Model.list = val; //foreach (Dictionary<string, object> s in val) //{ // Model.id = Convert.ToInt32(s["id"]); // Model.uid = Convert.ToInt32(s["uid"]); // Model.cid = Convert.ToInt32(s["cid"]); // Model.firstTime = Convert.ToDateTime(s["firstTime"]); // Model.lastTime = Convert.ToDateTime(s["lastTime"]); // Model.isDrop = Convert.ToBoolean(s["isDrop"]); // object a= s["values"]; // Dictionary<string, object> values= a as Dictionary<string, object>; // Model.x_title = values["x.title"].ToString(); // Model.x_kind = Convert.ToInt32(values["x.kind"]); // Model.x_type = Convert.ToInt32(values["x.type"]); // Model.x_beginTime = Convert.ToDateTime(values["x.beginTime"]); // Model.x_endTime = Convert.ToDateTime(values["x.beginTime"]); // Model.x_address= values["x.address"].ToString(); // Model.x_mode = Convert.ToInt32(values["x.mode"]); // Model.x_isCharge = Convert.ToBoolean(values["x.isCharge"]); // Model.x_chargePrice = Convert.ToSingle(values["x.chargePrice"]); // Model.x_isClose = Convert.ToBoolean(values["x.isClose"]); // Model.x_coverSummary = values["x.coverSummary"].ToString(); // Model.x_coverImage = values["x.coverImage"].ToString(); // Model.x_readCount = Convert.ToInt32(values["x.readCount"]); // Model.x_praiseCount = Convert.ToInt32(values["x.praiseCount"]); // Model.p_nick = values["p.nick"].ToString(); // Model.p_sign = values["p.sign"].ToString(); // Model.p_sex = Convert.ToInt32(values["p.sex"]); // Model.p_image = values["p.image"].ToString(); //} // //HttpWebResponse response = HttpCode.CreatePostHttpResponse(url, null, Encoding.UTF8); // //Stream stream = response.GetResponseStream(); //获取响应的字符串流 // //StreamReader sr = new StreamReader(stream); //创建一个stream读取流 // //string html = sr.ReadToEnd(); //从头读到尾,放到字符串html return(View(Model)); }
public static ApiResult Failed(ErrorCode errorCode, object result, HttpCode httpCode = HttpCode.BadRequest) => new ApiResult { HttpCode = httpCode, Value = new ApiJsonResult <object>((int)errorCode, errorCode.GetDescription(), result) };
public ActionResult EventDetails() { EventDetailsInfo Model = new EventDetailsInfo(); int id = Convert.ToInt32(Request.QueryString["id"]); int clientPlatform = 4; //viewLite viewLite = new viewLite { frameName = "EcrpSole", viewName = "ProfileTable" }; //viewLite viewLite = new viewLite { frameName = "EcrpMain", viewName = "AfficheTable" }; //viewLite viewLite = new viewLite { frameName = "EcrpMain", viewName = "AfficheItemTable" }; viewLite viewLite = new viewLite { frameName = "EcrpMain", viewName = "SignItemTable" }; Dictionary <string, object> parameters = new Dictionary <string, object>(); parameters.Add("clientPlatform", clientPlatform); parameters.Add("viewLite", viewLite); parameters.Add("id", id); string jsonStr = ToJson.ScriptSerialize(parameters); string url = "Http://61.155.203.29:60214/service.svc/ReadDataById2"; string resultStr = HttpCode.Post(url, jsonStr); Dictionary <string, object> obj = JsonTo.ScriptDeserialize(resultStr); Model.value = obj; string value = obj["value"].ToString(); Dictionary <string, object> obj1 = JsonTo.ScriptDeserialize(value); Model.value = obj1; /*object转dic类型*/ object values = obj1["values"]; Dictionary <string, object> values1 = values as Dictionary <string, object>; Model.values = values1; string a = Model.values["x.title"].ToString(); Model.a = a; string content = values1["x.content"].ToString(); string chargeSetting = values1["x.chargeSetting"].ToString(); string signSetting = values1["x.signSetting"].ToString(); List <Dictionary <string, object> > val_content = JsonTo.ScriptDeserializeList(content); Model.val_content = val_content; foreach (Dictionary <string, object> cont in Model.val_content) { if (cont.ContainsKey("photographList")) { ArrayList photographList = cont["photographList"] as ArrayList; Model.photographList = photographList; foreach (Dictionary <string, object> photogl in Model.photographList) { string address1 = photogl["address"].ToString(); } } } Dictionary <string, object> val_chargeSetting = JsonTo.ScriptDeserialize(chargeSetting); ArrayList afficheChargeList = val_chargeSetting["afficheChargeList"] as ArrayList; Model.afficheChargeList = afficheChargeList; foreach (Dictionary <string, object> affichecl in Model.afficheChargeList) { float money = Convert.ToSingle(affichecl["money"]); string count = affichecl["count"].ToString(); string name = affichecl["name"].ToString(); int chargeIndex = Convert.ToInt32(affichecl["chargeIndex"]); } Dictionary <string, object> val_signSetting = JsonTo.ScriptDeserialize(signSetting); ArrayList afficheSignList = val_signSetting["afficheSignList"] as ArrayList; Model.afficheSignList = afficheSignList; foreach (Dictionary <string, object> affichesl in Model.afficheSignList) { string name = affichesl["name"].ToString(); int kind = Convert.ToInt32(affichesl["kind"]); string item = affichesl["item"].ToString(); } return(View(Model)); }
void SendResponse <T>(HttpCode code, T response) { AsyncWrite(HttpHelper.CreateResponse(code, Json.CreateString(response))); }
public DeleteRequest(string url, HttpCode expectedResponseCode, params RequestProperty[] props) : base(RequestType.Delete, url, expectedResponseCode, props) { }
internal Redirect(HttpCode code, string uri) : base(code, "text/plain", "Redirecting...") { Headers.Add("Location", uri); }
public ResourceResponse(HttpCode aStatus, string type, string aResource) : this(aStatus, type, Properties.Resources.ResourceManager, aResource) { }
internal Redirect(HttpCode code, IRequest request, string path) : this(code, $"http://{request.LocalEndPoint}{path}") { }
private Stream ProcessRanges(IResponse rangedResponse, ref HttpCode status) { var responseBody = rangedResponse.Body; var contentLength = GetContentLengthFromStream(responseBody); string ar; if (status != HttpCode.Ok && contentLength > 0 || !headers.TryGetValue("Range", out ar)) { return responseBody; } try { var m = bytes.Match(ar); if (!m.Success) { throw new InvalidDataException("Not parsed!"); } var totalLength = contentLength; var start = 0L; var end = totalLength - 1; if (!long.TryParse(m.Groups[1].Value, out start) || start < 0) { throw new InvalidDataException("Not parsed"); } if (m.Groups.Count != 3 || !long.TryParse(m.Groups[2].Value, out end) || end <= start || end >= totalLength) { end = totalLength - 1; } if (start >= end) { responseBody.Close(); rangedResponse = Error416.HandleRequest(this); return rangedResponse.Body; } if (start > 0) { responseBody.Seek(start, SeekOrigin.Current); } contentLength = end - start + 1; rangedResponse.Headers["Content-Length"] = contentLength.ToString(); rangedResponse.Headers.Add("Content-Range", String.Format("bytes {0}-{1}/{2}", start, end, totalLength)); status = HttpCode.Partial; } catch (Exception ex) { Warn(String.Format("{0} - Failed to process range request!", this), ex); } return responseBody; }
public HttpException(HttpCode code, string message) : base(message) { Code = code; }
public StringResponse(HttpCode aStatus, string aBody) : this(aStatus, "text/html; charset=utf-8", aBody) { }
public static ApiResult Failed(HttpCode httpCode, object result = null) => new ApiResult { HttpCode = httpCode, Value = new ApiJsonResult <object>((int)httpCode, httpCode.GetDescription(), result), };
public static ApiResult Failed(HttpCode httpCode, string errorMessage) => new ApiResult { HttpCode = httpCode, Value = new ApiJsonResult <object>((int)httpCode, errorMessage), };
internal Redirect(HttpCode code, IRequest request, string path) : this(code, string.Format("http://{0}{1}", request.LocalEndPoint, path)) { }
/// <summary> /// /// </summary> /// <param name="Url"></param> public void Redirect(string Url, HttpCode HttpCode) { if ((int)HttpCode < 300 || (int)HttpCode > 399) throw (new Exception("Invalid HTTP Code for Redirection : " + HttpCode)); Headers["Location"] = Url; throw (new HttpException(HttpCode)); }