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

  • Home
  • SEARCH
  • 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 6804799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:30:36+00:00 2026-05-26T19:30:36+00:00

Question is really simple. What is Request.InputStream and when to use it. Is it

  • 0

Question is really simple. What is Request.InputStream and when to use it. Is it always used to read entire html body sent in the post request or only some parameters sent in it? Why should i not send data as a parameter to my server side code by passing it in the Ajax request?

In the example i can either pass the parameter in the data: or i can read the parameter in the Request.InputStream. When should i use which one?

Example:

In controller:

    public ActionResult GetSomeData(string someData)
    {
        Request.InputStream.Position = 0;
        System.IO.StreamReader str = new System.IO.StreamReader(Request.InputStream);
        string sBuf = str.ReadToEnd();
        return Json("something");
    }

Ajax Request:

        $.ajax({
            type: "POST",
            url: "Home/GetSomeData",
            data: "{someData:'Hello'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                alert(msg);
                // Insert the returned HTML into the <div>.
                $('#dvResult').html(msg);
            }
        });
  • 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-05-26T19:30:37+00:00Added an answer on May 26, 2026 at 7:30 pm

    Request.InputStream allows you to access the raw request data. If this data is formatted using some standard format such as application/x-www-form-urlencoded or multipart/form-data or some other format that the default model binder understands you do not need to use Request.InputStream. ASP.NET will parse the request values and you will be able to access them directly using Request[...]. Of course in ASP.NET MVC you don’t even need to use Request[...] because you can define a view model which your controller action will take as parameter and leave the model binder assign its properties from the request.

    There are cases though when you might want to access the raw request stream. For example you have invented some custom protocol and the client sends some custom formatted data in the request stream. Those cases are very rare since inventing custom protocols is not very common.

    Now back to your question. In your case you could define a view model:

    public class MyViewModel
    {
        public string SomeData { get; set; }
    }
    

    which your controller action will take as argument:

    public ActionResult GetSomeData(MyViewModel model)
    {
        // model.SomeData will contain the Hello string that the client sent
        return Json("something");
    }
    

    and on the client I would recommend you using the JSON.stringify method which is natively built into modern browsers to JSON serialize the request javascript literal into a JSON string instead of manually writing the JSON as you did:

    $.ajax({
        type: 'POST',
        url: 'Home/GetSomeData',
        data: JSON.stringify({ someData: 'Hello' }),
        contentType: 'application/json; charset=utf-8',
        success: function (msg) {
            alert(msg);
            // Insert the returned HTML into the <div>.
            $('#dvResult').html(msg);
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't let below code scare you away . The question is really simple, only
Simple question really - how do I use text_field_with_auto_complete inside a form_for block? I've
Really simple question - how do I do a search to find all records
simple question really, i was wanting to know what naming conventions anybody puts on
Really simple question: From within GWT I want to forward the user away from
This is a simple question really. I've been using the new type of constructors
This is probably a really simple question but... I would like to do a
This is a (hopefully) really simple question - I have been told recently that
I know this is a really simple question but my google-fu is failing me.
This sounds like a really simple question, but I am new to PHP. If

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.