What sets apart posting data through an HTML form submission from posting data through an Ajax request?

Recently, I've encountered an issue with my Post API. When calling it through AJAX, the user parameter is received but the StreamReader returns empty.

[HttpPost]
    [Route("getUserBankList")]
    public IHttpActionResult getUserBankList(UserProfile user)
    {
StreamReader reader = new StreamReader(HttpContext.Current.Request.InputStream);
      string getUserBankList = reader.ReadToEnd();
    }

Additionally, I have another Post API where data is sent via HTML form post. Surprisingly, the req parameter comes back as empty, but the StreamReader successfully retrieves the posted data.

[HttpPost]
    [Route("getUserBankList")]
    public IHttpActionResult ValidateToken(ValidateRequest req)
    {
StreamReader reader = new StreamReader(HttpContext.Current.Request.InputStream);
      string getUserBankList = reader.ReadToEnd();
    }

I'm puzzled by how differently the two POST requests are handled in terms of sending data. Any insights on this would be greatly appreciated!

Answer №1

After completing your action successfully, make sure to return a response from the action.

return Ok(getUserBankList);

Ensure you include the above line after receiving the response in reader.ReadToEnd()

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Use ag-Grid to customize your column headers with checkboxes, allowing you to easily select or deselect all items in that column. This feature is not limited to

In my experience with ag-grid, I often find myself needing to customize the first column header to include a checkbox. This allows me to easily perform actions such as selecting all or deselecting all rows in the grid. It's important to note that this ...

Automatically submit form in Javascript upon detecting a specific string in textarea

Just getting started with JS and I have a question that's been bugging me. I have a simple form set up like this: <form method="POST" action="foo.php"> <textarea name="inputBox123"></textarea> <input type="submit" value="Go" name ...

Difficulty in retrieving exceptions with FilterExceptionAttribute in Asp.net Web Api

I am encountering an issue where my exception becomes null while trying to retrieve it using ExceptionFilterAttribute. Here is the code snippet: using System.Net; using System.Net.Http; using System.Web.Http.Filters; using Newtonsoft.Json; using Presentat ...

Implementing a Vue.js v-bind:style attribute onto a dynamically generated element post-page initialization

Let me start by explaining my current issue and dilemma: I have been tasked with converting an existing JS project into a Vue.js framework. While I could easily solve a particular problem using jQuery, it seems to be posing quite a challenge when it comes ...

Utilize JavaScript/jQuery to check for upcoming deadlines in a SharePoint 2013 list

I need to check if an item is due based on its date. When a user creates an item with a date in the format MM/DD (e.g., 06/15), I want to determine if that date falls within the next 30 days, turning it red, within the next 60 days, turning it orange, or g ...

Tips for transferring a Spring MVC controller variable to JavaScript

I am currently working on retrieving a variable for a JavaScript function from an object that is sent to the view by the controller. The object I am dealing with is called Bpmsn. https://i.sstatic.net/FxlAo.png Through the controller, I have injected th ...

Node.js app not rendering ejs file despite using res.render() method, no error being thrown

I am encountering an issue where, when sending an ejs templated file as a response to a HTTP request, the HTML and CSS render properly but the Javascript does not respond. Even though the Javascript sources are linked in the head of the ejs response, the f ...

Leveraging the power of LARAVEL with AJAX by implementing a customized

As a newcomer to Laravel and Ajax, I've encountered an issue. When running the following script: $.ajax({ type : 'GET', url : 'getListeGenreCategorieAjax/'+$(this).val() , dataType : 'html', ...

What is the best way to develop a PHP proxy script to manage CORS problems when making API requests?

I am facing an issue where I need to call an API, but due to CORS problems, I have to create a PHP proxy file. However, the PHP code I wrote does not seem to be working as expected, leaving me stuck. Below is the script I'm using to make the API call ...

Issue with Jquery Crop: image not updating when using cropper

Here is the code I'm working with: <link rel="stylesheet" href="style.css"> <script src="/static/js/jquery/2.1.4/jquery.min.js"></script> <script src="http://fengyuanchen.github.io/cropper/js/cropper.min.js"></script> &l ...

If you want to use the decorators plugin, make sure to include the 'decoratorsBeforeExport' option in your

Currently, I am utilizing Next.js along with TypeScript and attempting to integrate TypeORM into my project, like demonstrated below: @Entity() export class UserModel extends BaseEntity { @PrimaryGeneratedColumn('uuid') id: number } Unfortun ...

Is there a way to halt the polling process for the specific API handling the background task?

I have been using this polling function for executing background tasks. export const poll = ({ fn = () => {}, validate = (result) => !!result, interval = 1000, maxAttempts = 15, }) => { let attempts = 1; // eslint-disable-next-line con ...

What is the process for determining the vertex position of geometry in three.js after applying translate, rotate, and scale transformations?

I've recently delved into the world of three.js. My current goal involves creating a curve within the scene and subsequently applying some transformations to it. The function responsible for generating the line is showcased below: var random_degree ...

Utilizing headless Chrome to automatically capture AJAX requests

Chrome officially supports running the browser in headless mode, allowing for programmatic control through the Puppeteer API and/or the CRI library. I've thoroughly explored the documentation but have not discovered a method to programmatically captu ...

How can I swap out a portion of a string in C#?

I'm facing a unique challenge in my game where players have custom codes for their clothing items. For example... hd-185-1.ch-235-1408.lg-3116-85-1408.ha-1002-1408.sh-3115-1408-1408.ca-1805-64. hd-185-12.ch-235-1408.lg-3116-85-1408.ha-1002-1408.sh-31 ...

Conceal a row within a TableLayout

I'm working with a table layout that consists of three rows and one column: https://i.sstatic.net/DzW5i.png My objective is to conceal the second row until the progress is completed, similar to this: https://i.sstatic.net/kKD2A.png After researchi ...

Issue with AngularJS: Local storage not saving updated contenteditable data

My local storage implementation stops working when I attempt to incorporate contentEditable feature. Here is the link to the CodePen for reference: https://codepen.io/zanderbush/pen/WNwWbWe. Any assistance would be greatly appreciated. The functionality w ...

Encountering issue with 'mongodb-connection-string-url'

As a beginner, I am struggling to understand the error message. When I try to run the app.js file, I receive the following log message. I read that I need to upgrade my MongoDB, but since I am using Windows 7, this seems impossible. PS G:\AWebDev&bsol ...

Why does my function consistently notify me that my answer is incorrect?

I've created a fun Pi quiz function that awards half a point for each correct digit you type. However, even if I enter just '3', it always shows as incorrect. Can someone assist me with this issue? function pi() { var piWithoutDecimals ...

Creating an interactive webpage with Javascript and HTML

I'm facing a challenge with my component setup, which is structured as follows: import { Component, VERSION } from '@angular/core'; @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: [ ...