/// <summary> /// 执行请求操作 /// </summary> public bool Execute() { Success = false; string response = string.Empty; Dictionary <string, string> parameters = constructParameters(); string request = string.Format("{0}/{1}?{2}", RequestDomain, Target, parameters.Join("&", p => p.Key + "=" + UrlEncode(p.Value))); if (RequireResquest) { try { Result = response = HttpRequestUtility.GetHttpResult(request, 10000); Success = parseResponse(response); } catch (Exception e) { Message = "失败。" + e.Message; LogService.SaveExceptionLog(e, "请求"); } } else { Result = response = request; Success = true; Message = "成功"; } //LogService.SaveTextLog(request + "\r\n\r\n" + Result); SaveLog(request, response, DateTime.Now); return(Success); }
/// <summary> /// 获取请求参数列表 /// </summary> /// <param name="actionDesc">接口描述</param> /// <returns></returns> protected NameValueCollection GetRequestParams(string actionDesc = "") { var queryStrings = Request.Content.ReadAsStringAsync().Result; if (string.IsNullOrEmpty(queryStrings)) { queryStrings = HttpUtility.UrlDecode(Request.RequestUri.Query.TrimStart('?'), Encoding.UTF8); } else { queryStrings = HttpUtility.UrlDecode(queryStrings, Encoding.UTF8); } LogUtil.Info(string.Format("{0}请求参数:{1}", actionDesc, queryStrings)); var sortDics = new SortedDictionary <string, object>(); var requestForms = HttpRequestUtility.GetNameValueCollection(queryStrings, out sortDics); if (requestForms.Keys.Count <= 0) { var msg = string.Format("{0}缺少参数!", actionDesc); LogUtil.Warn(msg); throw new MessageException(msg); } return(requestForms); }
public static async Task <IActionResult> CreateCart( [HttpTrigger(AuthorizationLevel.Function, "post", Route = "v1/carts")] HttpRequest req, [CosmosDB( databaseName: "smartretailboxmanagement", collectionName: "Terminals", ConnectionStringSetting = "CosmosDbConnectionString")] DocumentClient client, ILogger log) { var parameter = await HttpRequestUtility.GetRequestParameterAsync <CreateCartParameter>(req); var userRepo = new UserRepository(StaticHttpClient.Instance); var user = await userRepo.AuthenticateUserAsync(); if (!user.result.IsSuccess) { return(new UnauthorizedResult()); } var terminalRepo = new TerminalRepository(client); var terminal = await terminalRepo.FindByBoxIdAsync(parameter.BoxId); if (!terminal.result.IsSuccess) { return(ActionResultFactory.CreateError <CreateCartResponse>(terminal.result)); } var cartRepo = new CartRepository(new CartServiceApi(StaticHttpClient.Instance)); var cart = await cartRepo.CreateCartAsync(terminal.info.CompanyCode, terminal.info.StoreCode, terminal.info.TerminalNo, user.info.UserId, user.info.UserName); if (!cart.result.IsSuccess) { return(ActionResultFactory.CreateError <CreateCartResponse>(cart.result)); } var boxRepo = new BoxRepository(client); var updResult = await boxRepo.SetCartIdAsync(parameter.BoxId, parameter.DeviceId, user.info.UserId, cart.info.CartId); if (!updResult.IsSuccess) { return(ActionResultFactory.CreateError <CreateCartResponse>(updResult)); } await BoxUtility.RequestUnLockAsync(terminal.info.BoxId, terminal.info.BoxDeviceId); return(new CreatedResult( string.Empty, new CreateCartResponse { CartId = cart.info.CartId })); }
public static async Task <IActionResult> CreateCart( [HttpTrigger(AuthorizationLevel.Function, "post", Route = FunctionsRoute)] HttpRequest req, [CosmosDB(ConnectionStringSetting = CosmosDBConnectionStringSetting)] DocumentClient client, ILogger log) => await DoAsync(log, nameof(CreateCart), HttpStatusCode.Created, async() => { var param = await HttpRequestUtility.GetRequestParameterAsync <CreateCartParameter>(req); if (param == null) { return(new BadRequestObjectResult(Errors.ParameterError)); } return(await new PosLogic(log).CreateCartAsync(param, client)); });
public void Test2() { HttpRequestUtility httpRequestUtility = new HttpRequestUtility(); string usersList = httpRequestUtility.GetRequest(test2URL); bool emailIsFound = false; if (usersList.Contains("*****@*****.**")) { emailIsFound = true; } Assert.IsTrue(emailIsFound); }
public static async Task <IActionResult> AddItems( [HttpTrigger(AuthorizationLevel.Function, "post", Route = FunctionsRoute + "/{cartId}/items")] HttpRequest req, [CosmosDB(ConnectionStringSetting = CosmosDBConnectionStringSetting)] DocumentClient client, string cartId, ILogger log) => await DoAsync(log, nameof(AddItems), HttpStatusCode.OK, async() => { var param = await HttpRequestUtility.GetRequestParameterAsync <AddItemsParameter>(req); if (param == null) { return(new BadRequestObjectResult(Errors.ParameterError)); } return(await new PosLogic(log).AddItemsToCartAsync(param, client, cartId)); });
private string HttpRequest(string requestData) { Stopwatch stopwatch = Stopwatch.StartNew(); string result; try { result = HttpRequestUtility.Post("http://api.nexon.com:" + this._port + "/game/gameserver.aspx", this._serverAddress, requestData); } catch (Exception exception) { Logger.Log(exception); return(null); } Logger.Log("Request data:\r\n" + requestData); stopwatch.Stop(); Logger.Log("Elasped time " + stopwatch.Elapsed.TotalMilliseconds + "ms"); return(result); }
protected void btnCheck_Click(object sender, EventArgs e) { var fullText = txtMessage.Text; //replace new line fullText = fullText.Replace(Environment.NewLine, "$nl$"); var m = Regex.Match(fullText, @"hosts\..*Email"); var result = m.Value.Trim("host.Email$nl$,".ToArray()); JObject jObj = new JObject(); var cards = result.Split(new string[] { "$nl$" }, StringSplitOptions.RemoveEmptyEntries); if (cards.Length > 0) { for (int i = 1; i <= cards.Length; i++) { var split = Regex.Matches(cards[i - 1], @"[^\s]+"); if (split.Count == 4) { var jItem = new JObject { { "AccountNo", split[1].ToString() }, { "AccountName", split[2].ToString() }, { "IssueBankAddress", split[3].ToString().TrimEnd(',') }, }; jObj.Add($"Card{i.ToString()}", jItem); } } } //send request var request = new HttpRequestUtility { FormMethod = HttpMethod.Post, ContentType = "application/json", CharSet = "utf8", Url = $"{Request.Url.Scheme}://{Request.Url.Authority}{Request.Url.Segments.Aggregate((sum, next) => sum + next).Replace(Request.Url.Segments[Request.Url.Segments.Count() - 1], "Notify")}", FormContent = new StringContent(jObj.ToString(Newtonsoft.Json.Formatting.None)) }; using (var response = request.Submit()) { } lbMsg.Text = "Execution Result : submit successfully"; }
private string SendTeamsMsg(string text) { var content = new JObject { { "title", "Bank Card Verification" }, { "text", text } }; var request = new HttpRequestUtility() { FormMethod = HttpMethod.Post, ContentType = "application/json", FormContent = new StringContent(content.ToString()), Url = teamsUrl, Timeout = 3 }; using (var resp = request.Submit()) { } return(text); }