public WebSendRecvRequest(WebMethods method, string url, CancellationToken cancel = default, string uploadContentType = Consts.MimeTypes.OctetStream, Stream?uploadStream = null, long?rangeStart = null, long?rangeLength = null) { if (rangeStart == null && rangeLength != null) { throw new ArgumentOutOfRangeException("rangeStart == null && rangeLength != null"); } if ((rangeStart ?? 0) < 0) { throw new ArgumentOutOfRangeException(nameof(rangeStart)); } if ((rangeLength ?? 1) <= 0) { throw new ArgumentOutOfRangeException(nameof(rangeLength)); } this.RangeStart = rangeStart; this.RangeLength = rangeLength; checked { Limbo.SInt64 = this.RangeStart ?? 0 + this.RangeLength ?? 0; } this.Method = method; this.Url = url; this.Cancel = cancel; this.UploadContentType = uploadContentType._FilledOrDefault(Consts.MimeTypes.OctetStream); this.UploadStream = uploadStream; }
static async Task StandardRequestHandlerAsync(HttpRequest request, HttpResponse response, RouteData routeData, HttpResultStandardRequestAsyncCallback callback) { WebMethods method = request.Method._ParseEnum(WebMethods.GET); CancellationToken cancel = request._GetRequestCancellationToken(); ConnectionInfo connInfo = request.HttpContext.Connection; IPEndPoint remote = new IPEndPoint(connInfo.RemoteIpAddress._UnmapIPv4(), connInfo.RemotePort); IPEndPoint local = new IPEndPoint(connInfo.LocalIpAddress._UnmapIPv4(), connInfo.LocalPort); string pathAndQueryString = request._GetRequestPathAndQueryString(); pathAndQueryString._ParseUrl(out Uri uri, out QueryStringList qs); try { using (HttpResult result = await callback(method, uri.LocalPath, qs, routeData, local, remote, cancel)) { await response._SendHttpResultAsync(result, cancel); } } catch (Exception ex) { ex._Error(); HttpResult errResult = new HttpStringResult("Error: " + ex.Message, statusCode: Consts.HttpStatusCodes.InternalServerError); await response._SendHttpResultAsync(errResult, cancel); } }
public static List <string> GetBusinessName(string businessName) { List <string> businessNameList = new List <string>(); businessNameList = WebMethods.FetchBusinessNameFromDB(businessName); return(businessNameList); }
public IHttpActionResult GetMandatoryHolidayListDetails(MandatoryHolidayList emp) { var response_from_holiday = MandatoryHolidayRepository.GetMandatoryHolidayListDetails(emp.EmpID); var response = WebMethods.CreateServiceResponse(Enums.WebServiceStatus.Success, response_from_holiday); return(Json(response)); }
private async void button1_Click(object sender, EventArgs e) { string Cedula = "21128030"; string Url = "http://www.cne.gob.ve/web/registro_electoral/ce.php?nacionalidad=V&cedula=" + Cedula; string result = await WebMethods.GetResquest(Url, 10); }
/// <summary> /// Sends post data to back-end request /// </summary> protected virtual void ApplyPostDataToRequest(WebRequest webRequest) { // Only if this is post if (WebMethods.IsMethod(RequestInfo.RequestMethod, WebMethods.DefaultMethods.POST)) { if (RequestInfo.InputStream != null) { Stream reqStream = webRequest.GetRequestStream(); // Read stream then reset renamed ViewState name to default byte[] inputBytes = Common.AspDotNetViewStateResetToDef(RequestInfo.InputStream); // Write to destination stream reqStream.Write(inputBytes, 0, inputBytes.Length); reqStream.Close(); RequestInfo.InputStream.Close(); } else { string postData = Common.AspDotNetViewStateResetToDef(RequestInfo.PostDataString); byte[] bytes = Encoding.ASCII.GetBytes(postData); webRequest.ContentLength = bytes.LongLength; Stream reqStream = webRequest.GetRequestStream(); reqStream.Write(bytes, 0, bytes.Length); reqStream.Close(); } } }
public static List <string> GetBusinessCode(string businessCode) { List <string> businessCodeList = new List <string>(); businessCodeList = WebMethods.FetchBusinessCodeFromDB(businessCode); return(businessCodeList.ToList <string>()); }
public IHttpActionResult BotAuthenticationDetails(BotAuthenticationModal id) { BotAuthenticationRepository sa = new BotAuthenticationRepository(); var r = sa.GetLoginDetails(id.loginID, id.password); var response = WebMethods.CreateServiceResponse(Enums.WebServiceStatus.Success, r); return(Json(response)); }
public WebSendRecvRequest(WebMethods method, string url, CancellationToken cancel = default, string uploadContentType = Consts.MimeTypes.OctetStream, Stream?uploadStream = null) { this.Method = method; this.Url = url; this.Cancel = cancel; this.UploadContentType = uploadContentType._FilledOrDefault(Consts.MimeTypes.OctetStream); this.UploadStream = uploadStream; }
public IHttpActionResult DimattendancemonthlyDetails(DimattendancemonthlyModel id) { DimattendancemonthlyRepository sa = new DimattendancemonthlyRepository(); var r = sa.GetMonthlyAttendanceDetails(id.EmpID); var response = WebMethods.CreateServiceResponse(Enums.WebServiceStatus.Success, r); return(Json(response)); }
public IHttpActionResult Probation_period_details(Probation_periodModal id) { Profile_Prob_JoinRepository sa = new Profile_Prob_JoinRepository(); var r = sa.GetProfileDetails(id.empID); var response = WebMethods.CreateServiceResponse(Enums.WebServiceStatus.Success, r); return(Json(response)); }
public static async Task <HttpResponseMessage> Upload(string table_name, object obj) { var json = Newtonsoft.Json.JsonConvert.SerializeObject(new { TableName = table_name, Content = obj }); return(await WebMethods.Request(HttpMethod.Post, Url, json)); }
public async Task <WebRet> DownloadAsync(WebMethods method, PrivKey key, string?kid, string url, object?request, CancellationToken cancel = default) { string nonce = await GetNonceAsync(cancel); //("*** " + url)._Debug(); WebRet webret = await Web.RequestWithJwsObjectAsync(method, key, kid, nonce, url, request, cancel, Consts.MimeTypes.JoseJson); return(webret); }
public IHttpActionResult GetProbationPeriodDetails(EmployeeDetails emp) { var response_from_stored_proc = StoredProcedureRepository.GetEmployeeDetails(emp.EmpID); if (response_from_stored_proc == null) { return(NotFound()); } var response = WebMethods.CreateServiceResponse(Enums.WebServiceStatus.Success, response_from_stored_proc); return(Json(response)); }
public IHttpActionResult GetProduct(TestRequest test) { var product = products.FirstOrDefault((p) => p.Id == test.id); if (product == null) { return(NotFound()); } var response = WebMethods.CreateServiceResponse(Enums.WebServiceStatus.Success, product); return(Json(response)); }
public void SetOnlineDocumentsToLocal() { WebMethods webapi = new WebMethods(); webapi.GetPolicies(); webapi.policysEvent += ((WebMethods webAPISender, EventArgs e2) => { Device.BeginInvokeOnMainThread(() => { PolicyModel.DocType[] PolicyDocTypes = SimpleJson.DeserializeObject <PolicyModel.DocType[]>(webAPISender.Polocysresponse); List <Policies> OfflineList = new List <Policies>(); foreach (PolicyModel.DocType dst in PolicyDocTypes) { DataItems = new ObservableCollection <DocumentItem>(); int i = 0; PolicySubTypes = new string[5]; foreach (PolicyModel.DocSubType pd in dst.DocSubTypes) { PolicySubTypes[i] = pd.Name.ToString(); DocumentType dt3 = new DocumentType { DocumentTypeId = i, DocumentTypeTitle = pd.Name.ToString() }; int j = 0; foreach (PolicyModel.Document orgDoc in pd.Documents) { DocumentItem pdi = new DocumentItem(); pdi.DocumentItemId = j; pdi.DocumentItemTitle = orgDoc.DocumentName; pdi.DocumentType = dt3; DataItems.Add(pdi); Policies OfflineSingleP = new Policies(); OfflineSingleP.DocName = orgDoc.DocumentName; OfflineList.Add(OfflineSingleP); OfflineSingleP = null; j = j + 1; } i = i + 1; } } //PoliciesRepository pr = new PoliciesRepository(); //pr.AddAllPolicies(OfflineList); }); }); }
/// <summary> /// Initializes the request info post data. /// </summary> protected virtual void IntializeRequestInfoPostData(HttpRequest httpRequest) { if (httpRequest != null) { // TODO: test this case // When a post back event occurred "httpRequest.ContentType" contains ContentType of request // In other cases the "httpRequest.ContentType" is empty and we shouldn't use this property if (!string.IsNullOrEmpty(httpRequest.ContentType)) { RequestInfo.SetContentType(httpRequest.ContentType); } RequestInfo.InputStream = httpRequest.InputStream; // Get posted form data string string httpRequestMethod = httpRequest.HttpMethod; if (WebMethods.IsMethod(httpRequestMethod, WebMethods.DefaultMethods.POST)) { RequestInfo.PostDataString = httpRequest.Form.ToString(); // Some web sites encodes the url, and we need to decode it. //RequestInfo.PostDataString = HttpUtility.HtmlDecode(RequestInfo.PostDataString); // Since V5.5 // The text should be decoded before any use RequestInfo.PostDataString = UnicodeUrlDecoder.UrlDecode(RequestInfo.PostDataString); // BUG: not working with (#) and (&) characters //RequestInfo.PostDataString = HttpUtility.UrlDecode(RequestInfo.PostDataString); } else { RequestInfo.PostDataString = ""; } } else { RequestInfo.PostDataString = ""; } // If requested method is GET if (WebMethods.IsMethod(RequestInfo.RequestMethod, WebMethods.DefaultMethods.GET)) { // Apply filter for ASP.NET pages // Change requested url by posted data RequestInfo.RequestUrl = UrlBuilder.AppendAntoherQueries(RequestInfo.RequestUrl, RequestInfo.PostDataString); } }
protected WebApplication() { var helperTypes = getHelpers(); //TODO better helpers handling var helperTypesList = new List <Type>(); helperTypesList.AddRange(helperTypes); helperTypesList.Add(typeof(CompilerHelpers)); var webHelpers = new WebMethods(helperTypesList.ToArray()); HandlerProvider = new ResponseHandlerProvider(webHelpers); }
public IHttpActionResult UserLogin(AuthenticationRequest objAuthenticationRequest) { AuthenticationRequest au = new AuthenticationRequest(); ServiceResponse response = null; try { if (string.IsNullOrEmpty(objAuthenticationRequest.UserName)) { ModelState.AddModelError("UserName", "Please Enter Username."); } if (objAuthenticationRequest.AuthenticationType.ToLower() == "FORM" && string.IsNullOrEmpty(objAuthenticationRequest.Password)) { ModelState.AddModelError("Password", "Please Enter Password."); } if (!ModelState.IsValid) { List <string> modelErrors = new List <string>(); foreach (var modelState in ModelState.Values) { foreach (var modelError in modelState.Errors) { modelErrors.Add(modelError.ErrorMessage); } } response = WebMethods.CreateServiceResponse(Enums.WebServiceStatus.Invalid, modelErrors); } else { AuthenticationResponse objAuthenticationResponse = new AuthenticationResponse(); string Token = JwtManager.GenerateToken(objAuthenticationRequest.UserName, Convert.ToInt32(ConfigurationManager.AppSettings["TokenExpireMinutes"])); objAuthenticationResponse.AuthorizationToken = "Bearer " + Token; response = WebMethods.CreateServiceResponse(Enums.WebServiceStatus.Success, objAuthenticationResponse); } } catch (Exception ex) { List <string> ErrorList = new List <string>(); ErrorList.Add(ex.Message); response = WebMethods.CreateServiceResponse(Enums.WebServiceStatus.ServerError, ErrorList); } return(Json(response)); }
public void Test_WebMethod_Post_With_Json_Config() { WebMethods.ConfigurationBuilderFunc = (context, builder) => builder.AddJsonFile("testconfig.json", false); WebMethods = new WebMethods(); Assert.Equal("TESTACCESSKEY", WebMethods.awsCredentials.AccessKey); Assert.Equal("TESTSECRETKEY", WebMethods.awsCredentials.SecretKey); Assert.Equal("arn:aws:sns:us-east-1:TEST:TestFeed", WebMethods.awsSns.Topic); var response = WebMethods.Post(RequestMock.Object, ContextMock.Object); Assert.Equal((int)HttpStatusCode.OK, response.StatusCode); SnsMock.Verify(); }
public async Task <WebUserRet <TResponse> > RequestAsync <TResponse>(WebMethods method, PrivKey key, string?kid, string url, object?request, CancellationToken cancel = default) { string nonce = await GetNonceAsync(cancel); //("*** " + url)._Debug(); WebRet webret = await Web.RequestWithJwsObject(method, key, kid, nonce, url, request, cancel, Consts.MimeTypes.JoseJson); TResponse ret = webret.Deserialize <TResponse>(true); //webret.Headers._DebugHeaders(); //webret.ToString()._Debug(); return(webret.CreateUserRet(ret)); }
public void Test_WebMethod_Default_Create() { var called = false; Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", null); WebMethods.ConfigurationBuilderFunc = (hostingContext, builder) => { called = true; Assert.True(hostingContext.HostingEnvironment.IsDevelopment()); return(builder); }; WebMethods = new WebMethods(); Assert.True(called); }
public void Test_WebMethod_Post_With_Environment_Config() { Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Production"); Environment.SetEnvironmentVariable("WEBHOOK_AWSCREDENTIALS:ACCESSKEY", "TestAccessKey"); Environment.SetEnvironmentVariable("WEBHOOK_AWSCREDENTIALS:SECRETKEY", "TestSecretKey"); Environment.SetEnvironmentVariable("WEBHOOK_AWSSNS:TOPIC", "TestSnsTopic"); WebMethods.ConfigurationBuilderFunc = (context, builder) => builder.AddEnvironmentVariables("WEBHOOK_"); WebMethods = new WebMethods(); Assert.Equal("TestAccessKey", WebMethods.awsCredentials.AccessKey); Assert.Equal("TestSecretKey", WebMethods.awsCredentials.SecretKey); Assert.Equal("TestSnsTopic", WebMethods.awsSns.Topic); var response = WebMethods.Post(RequestMock.Object, ContextMock.Object); Assert.Equal((int)HttpStatusCode.OK, response.StatusCode); SnsMock.Verify(); }
//Get method: queryParameters, Post method: bodyContent //queryParameters: using dictionary and set key to query name, value to query value public static ReturnString GetResult(string baseUrl, WebMethods method, dynamic queryParameters = null, dynamic bodyContent = null) { string url = string.Empty; if (queryParameters != null) { url = BuildUrl(baseUrl, queryParameters); } else { url = baseUrl; } var request = (HttpWebRequest)HttpWebRequest.Create(url); request.Method = method.ToString(); request.ContentType = "application/json"; request.Accept = "application/json"; try { if (bodyContent != null) { string contentString = string.Empty; if (bodyContent is String) { contentString = bodyContent; } else { contentString = JsonConvert.SerializeObject(bodyContent); } using (var writer = new StreamWriter(request.GetRequestStream())) { writer.Write(contentString); } } var response = request.GetResponse(); using (var reader = new StreamReader(response.GetResponseStream())) { var responseContent = reader.ReadToEnd(); var result = new ReturnString(); try { if (!string.IsNullOrWhiteSpace(responseContent)) { result.result = responseContent; } } catch (Exception ex) { throw ex; } return(result); } } catch (WebException webException) { throw webException; } }
public async Task <HttpResult> PostHandlerAsync(WebMethods method, string path, QueryStringList queryString, HttpContext context, RouteData routeData, IPEndPoint local, IPEndPoint remote, CancellationToken cancel = default) { var request = context.Request; string str = await request._RecvStringContentsAsync(CoresConfig.DataVaultServerApp.MaxHttpPostRecvData, cancel : cancel); DataVaultData?recv = str._JsonToObject <DataVaultData>(); List <DataVaultData> list = new List <DataVaultData>(); if (recv != null) { recv.NormalizeReceivedData(); recv.StatGitCommitId = recv.StatGitCommitId._NonNullTrim(); recv.StatAppVer = recv.StatAppVer._NonNullTrim(); recv.TimeStamp = DtOffsetNow; recv.StatGlobalIp = remote.Address.ToString(); recv.StatGlobalPort = remote.Port; recv.StatGlobalFqdn = await LocalNet.GetHostNameSingleOrIpAsync(recv.StatGlobalIp, cancel); recv.StatLocalIp = recv.StatLocalIp._NonNullTrim(); if (recv.StatLocalIp._IsEmpty()) { recv.StatLocalIp = "127.0.0.1"; } recv.StatLocalFqdn = recv.StatLocalFqdn._NonNullTrim(); if (recv.StatLocalFqdn._IsEmpty()) { recv.StatLocalFqdn = "localhost"; } recv.StatUid = recv.StatUid._NonNullTrim(); if (recv.SystemName._IsFilled() && recv.LogName._IsFilled()) { // キー無し 1 つのディレクトリに全部書き込み try { DataVaultData d = recv._CloneIfClonable(); d.KeyType = "all"; d.KeyShortValue = "all"; d.KeyFullValue = "all"; list.Add(d); } catch (Exception ex) { ex._Debug(); } // UID からキーを生成 try { DataVaultData d = recv._CloneIfClonable(); d.KeyType = "by_uid"; d.KeyShortValue = recv.StatUid._TruncStr(2); d.KeyFullValue = recv.StatUid._TruncStr(4); list.Add(d); } catch (Exception ex) { ex._Debug(); } // グローバル IP からキーを生成 try { DataVaultData d = recv._CloneIfClonable(); d.KeyType = "by_global_ip"; d.KeyShortValue = IPUtil.GetHead1BytesIPString(recv.StatGlobalIp); d.KeyFullValue = IPUtil.GetHead2BytesIPString(recv.StatGlobalIp); list.Add(d); } catch (Exception ex) { ex._Debug(); } // グローバル FQDN からキーを生成 try { string shortKey, longKey; if (IPUtil.IsStrIP(recv.StatGlobalFqdn) == false) { // FQDN if (MasterData.DomainSuffixList.ParseDomainBySuffixList(recv.StatGlobalFqdn, out string tld, out string domain, out string hostname)) { // 正しい TLD 配下のドメイン // 例: 12345.abc.example.org の場合 // Short key は org.example.ab // Long key は org.example.abc.1 string domainReverse = domain._Split(StringSplitOptions.RemoveEmptyEntries, '.').Reverse()._Combine("."); string hostnameReverse = hostname._Split(StringSplitOptions.RemoveEmptyEntries, '.').Reverse()._Combine("."); shortKey = new string[] { domainReverse, hostnameReverse._TruncStr(2) }._Combine("."); longKey = new string[] { domainReverse, hostnameReverse._TruncStr(5) }._Combine("."); } else { // おかしなドメイン shortKey = recv.StatGlobalFqdn._TruncStr(2); longKey = recv.StatGlobalFqdn._TruncStr(4); } } else { // IP アドレス shortKey = IPUtil.GetHead1BytesIPString(recv.StatGlobalIp); longKey = IPUtil.GetHead1BytesIPString(recv.StatGlobalIp); } DataVaultData d = recv._CloneIfClonable(); d.KeyType = "by_global_fqdn"; d.KeyShortValue = shortKey; d.KeyFullValue = longKey; list.Add(d); }
public Task <WebUserRet <TResponse> > RequestAsync <TResponse>(WebMethods method, string url, object?request, CancellationToken cancel = default) { return(this.Client.RequestAsync <TResponse>(method, this.PrivKey, this.AccountUrl, url, request, cancel)); }
public static async Task <SimpleHttpDownloaderResult> DownloadAsync(string url, WebMethods method = WebMethods.GET, bool printStatus = false, WebApiOptions?options = null, RemoteCertificateValidationCallback?sslServerCertValicationCallback = null, CancellationToken cancel = default, string?postContentType = Consts.MimeTypes.FormUrlEncoded, params (string name, string?value)[] queryList)
public async Task <byte[]> DownloadAsync(WebMethods method, string url, CancellationToken cancel = default) { WebRet ret = await Web.SimpleQueryAsync(method, url, cancel); return(ret.Data); }
private void GetOnlineDocuments() { WebMethods webapi = new WebMethods(); if (DataItems != null) { SetDocumentDetails(); } else { webapi.GetPolicies(); } webapi.policysEvent += ((WebMethods webAPISender, EventArgs e2) => { Device.BeginInvokeOnMainThread(() => { PolicyModel.DocType[] PolicyDocTypes = SimpleJson.DeserializeObject <PolicyModel.DocType[]>(webAPISender.Polocysresponse); List <Policies> OfflineList = new List <Policies>(); foreach (PolicyModel.DocType dst in PolicyDocTypes) { DataItems = new ObservableCollection <DocumentItem>(); int i = 0; PolicySubTypes = new string[5]; foreach (PolicyModel.DocSubType pd in dst.DocSubTypes) { PolicySubTypes[i] = pd.Name.ToString(); DocumentType dt3 = new DocumentType { DocumentTypeId = i, DocumentTypeTitle = pd.Name.ToString() }; int j = 0; foreach (PolicyModel.Document orgDoc in pd.Documents) { //await App.PersonRepo.AddNewPersonAsync(orgDoc.DocumentName); DocumentItem pdi = new DocumentItem(); pdi.DocumentItemId = j; pdi.DocumentItemTitle = orgDoc.DocumentName; pdi.DocumentType = dt3; DataItems.Add(pdi); //from here Policies OfflineSingleP = new Policies(); OfflineSingleP.DocName = orgDoc.DocumentName; OfflineList.Add(OfflineSingleP); OfflineSingleP = null; //till here j = j + 1; } i = i + 1; } //DocumentTypes = new ObservableCollection<Grouping<SelectDocumentTypeViewModel, DocumentItem>>(); if (DataItems != null) { SetDocumentDetails(); } } }); }); }
protected override HttpRequestMessage CreateWebRequest(WebMethods method, string url, params (string name, string?value)[]?queryList)