简体   繁体   中英

What is difference is posting data via html form post and Ajax post?

I have Post API like below. I am calling this via AJAX and I get request in user parameter but StreamReader comes as empty.

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

I have another Post API like below. I am calling this via HTML form post but I get req parameter as empty but StreamReader is able to fetch posted data.

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

Could anybody please explain how in above two differnt post data is getting send.

You didn't return any thing form action after successfully execute your's action.

return Ok(getUserBankList);

Please add above line after getting the response in reader.ReadToEnd()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM