public responseData reserves(requestData r) { responseData rd = new responseData(); try { rd.data.AddRange(DataRPC.getReserves(r.yearFrom, r.yearTo)); } catch (Exception ex) { rd.error = ex.Message; } finally { } return(rd); }
public responseData productionByCountry(requestData r) { responseData rd = new responseData(); try { rd.data.AddRange(DataRPC.getProductionCountry(r.by, r.yearFrom, r.yearTo)); } catch (Exception ex) { rd.error = ex.Message; } finally { } return(rd); }
public Task <responseData> Login(string entryUser, string entryPass) { try { //RestClient Cliente = new RestClient("http://172.16.20.108/api"); RestClient Cliente = new RestClient("http://youis.000webhostapp.com/Project/Utap/api/"); RestRequest request = new RestRequest("/utap0-0.php", Method.POST) { RequestFormat = DataFormat.Json }; request.AddParameter("email", entryUser); request.AddParameter("password", entryPass); var response = Cliente.Execute(request); responseData contenido = JsonConvert.DeserializeObject <responseData>(response.Content); return(Task.FromResult(contenido)); } catch (Exception) { return(null); } }
await dataStream.WriteMessageAsync(impl.ConnectionStateUInt, errData, responseData, ct).ConfigureAwait(false);
public async Task <IActionResult> Upload() { if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType)) { return(BadRequest($"Expected a multipart request, but got '{Request.ContentType}'.")); } // Used to accumulate all the form url encoded key value pairs in the request. var formAccumulator = new KeyValueAccumulator(); string targetFilePath = null; var boundary = MultipartRequestHelper.GetBoundary( MediaTypeHeaderValue.Parse(Request.ContentType), _defaultFormOptions.MultipartBoundaryLengthLimit); var reader = new MultipartReader(boundary.Value, HttpContext.Request.Body); var section = await reader.ReadNextSectionAsync(); while (section != null) { ContentDispositionHeaderValue contentDisposition; ContentDispositionHeaderValue.TryParse(section.ContentDisposition, out contentDisposition); if (MultipartRequestHelper.HasFileContentDisposition(contentDisposition)) { var name = HeaderUtilities.RemoveQuotes(contentDisposition.Name); if (!name.HasValue) { name = string.Empty; } var fileName = HeaderUtilities.RemoveQuotes(contentDisposition.FileName); if (!name.HasValue) { fileName = string.Empty; } // Here the uploaded file is being copied to local disk but you can also for example, copy the // stream directly to let's say Azure blob storage targetFilePath = Path.Combine(_hostingEnvironment.ContentRootPath, Guid.NewGuid().ToString()); using (var targetStream = System.IO.File.Create(targetFilePath)) { await section.Body.CopyToAsync(targetStream); _logger.LogInformation($"Copied the uploaded file '{fileName}' to '{targetFilePath}'."); } } else if (MultipartRequestHelper.HasFormDataContentDisposition(contentDisposition)) { // Content-Disposition: form-data; name="key" // // value // Do not limit the key name length here because the mulipart headers length // limit is already in effect. var key = HeaderUtilities.RemoveQuotes(contentDisposition.Name); MediaTypeHeaderValue mediaType; MediaTypeHeaderValue.TryParse(section.ContentType, out mediaType); var encoding = FilterEncoding(mediaType?.Encoding); using (var streamReader = new StreamReader( section.Body, encoding, detectEncodingFromByteOrderMarks: true, bufferSize: 1024, leaveOpen: true)) { // The value length limit is enforced by MultipartBodyLengthLimit var value = await streamReader.ReadToEndAsync(); formAccumulator.Append(key.Value, value); //if (formAccumulator.KeyCount > _defaultFormOptions.KeyCountLimit) //{ // throw new InvalidDataException( // $"Form key count limit {_defaultFormOptions.KeyCountLimit} exceeded."); //} } } // Drains any remaining section body that has not been consumed and // reads the headers for the next section. section = await reader.ReadNextSectionAsync(); } // Bind form data to a model var user = new User(); var formValueProvider = new FormValueProvider( BindingSource.Form, new FormCollection(formAccumulator.GetResults()), CultureInfo.CurrentCulture); var bindingSuccessful = await TryUpdateModelAsync(user, prefix : "", valueProvider : formValueProvider); if (!bindingSuccessful) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } } var responseData = new responseData() { Name = user.Name, Age = user.Age, Zipcode = user.Zipcode, FilePath = targetFilePath }; return(Json(responseData)); }