Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8004109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:49:46+00:00 2026-06-04T16:49:46+00:00

I had [HttpPost] public ActionResult Foo() { // read HTTP payload var reqMemStream =

  • 0

I had

[HttpPost]        
public ActionResult Foo()
{
    // read HTTP payload
    var reqMemStream = new MemoryStream(HttpContext.Request.BinaryRead(HttpContext.Request.ContentLength));
 ....
}

The payload is application/json; worked fine; then I changed to

public ActionResult Foo(string thing)
{
....
}

The intention being to post to MyController/Foo?thing=yo
Now I cant read the payload(the length is correct but the stream is empty). My guess is that the controller plumbing has eaten the payload looking for form post data that can be mapped to the method parameters. Is there some way that I can stop this behavior (surely MVC should not have eaten a payload whose type is marked as JSON , it should only look at form post data). My work around is to add ‘thing’ to the json but I dont really like that

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:49:47+00:00Added an answer on June 4, 2026 at 4:49 pm

    Try resetting the input stream position before reading:

    public ActionResult Foo(string thing)
    {
        Request.InputStream.Position = 0;
        var reqMemStream = new MemoryStream(HttpContext.Request.BinaryRead(HttpContext.Request.ContentLength));
        ....
    }
    

    Now this being said, if you are sending an application/json payload why on the holy Earth are you bothering to read directly the request stream instead of simply defining and using a view model:

    public class MyViewModel
    {
        public string Thing { get; set; }
        public string Foo { get; set; }
        public string Bar { get; set; }
        ...
    }
    

    and then:

    public ActionResult Foo(MyViewModel model)
    {
        // use the model here 
        ....
    }
    

    ASP.NET MVC 3 has a built-in JsonValueProviderFactory which allows you to automatically bind JSON requests to models. And if you are using an older version it is trivially easy to add such factory your self as Phil Haack illustrates in his blog post.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here is my root controller : [HttpPost] public ActionResult Index() { } but it
I have an [HttpPost] action method signature like this: [HttpPost] public ActionResult Edit(ExistingPostViewModel model)
We had a View Model that looked like this: public class myViewModel { public
i'm trying to send an http request from an Android app to a Java
I am trying to create an HTTP POST request in android where I pass
Had a page that was working fine. Only change I made was to add
Had a good search here but can't see anything that gets my mind in
Had a problem with the recursive conflictCheck() method. That seems fine now. I have
Had this working; at one stage. The problem is the following text is now
I had a Navigation Controller based application and decided to use tab bars. And

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.