skip to Main Content

How to set a JsonSerializerOptions globally for my httpClient.GetFromJsonAsync<T> calls

In my ASP.NET web API I have httpClient which call GetFromJsonAsync: var jsonSerializerOptions = new JsonSerializerOptions { PropertyNameCaseInsensitive = true, }; jsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); await httpClient.GetFromJsonAsync<Item[]>(uri, jsonSerializerOptions); It is quite repetitive to add the jsonSerializerOptions parameter in all my GetFromJsonAsync calls…

VIEW QUESTION

Http Post Json in VS2022 C#

I have json file. When I send it by Postman (Application) it works but in C# code I get "Bad Request" The Json File: { "name": "Token", "request": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/x-www-form-urlencoded" }, {…

VIEW QUESTION

How to post selected checkboxes as an array from angular to api – Html

I've created a component "form-page" in the "form" module: form-page.component.html: <form [formGroup]="form" (submit)="onSubmit()"> <div> <label for="carmodel">Car Model:</label> <input type="text" class="form-control" formControlName="carmodel"> <div *ngIf="form.controls['carmodel'].touched && form.controls['carmodel'].errors"> <div *ngIf="form.controls['carmodel'].hasError('required')" class="error">Carmodel is required.</div> <div *ngIf="form.controls['carmodel'].hasError('minlength')">Carmodel should be minimum 3 characters.</div> </div> </div> <div>…

VIEW QUESTION

Json – C# Not able to post data using HttpRequestMessage and getting 400 status

I tried a few different ways I can't get pipelineId to post (receive 400), see code below: { client.BaseAddress = new Uri(_serviceConfig.DataGapsBaseUrl); var request = new HttpRequestMessage(HttpMethod.Post, "/piper/jobs"); var jsonContent = new StringContent(JsonConvert.SerializeObject(new { pipelineId = _serviceConfig.DataPipelineId }), Encoding.UTF8, "application/json");…

VIEW QUESTION

Angular 15 file upload into laravel 10 $request->file('image') return null

Im trying to upload a image from angular onImageCahnge(event: any): void { if (event.target.files.length > 0) { const file = event.target.files[0]; this.herosliderForm.patchValue({ imageSource: file }); } } on submit const formData = new FormData(); formData.append('image', this.herosliderForm.get('image')?.value) this.herosliderService.update(this.herosliderForm.value.id, formData).subscribe({ next: (response:…

VIEW QUESTION
Back To Top
Search