简体   繁体   中英

How to change the content-length in a header value in asp.net?

I need to set the content-length property of the header value of a asp.net aspx page to 100 but the client said they can receive it as 20. But I am quite new in this. So, I would like to know how I may change this content-length of a aspx page? Because the aspx page is actually blank in html only the .cs file got code to work with the incoming request string. But the client complained that they have read that the content=length is only 20 so it is only reading upto 20 character not after that. Please help me on this. My aspx page only have this line:

  <%@ Page Language="C#"  AutoEventWireup="true" CodeFile="MT.aspx.cs" Inherits="_Default" 
   ValidateRequest="false" EnableEventValidation="false" %>

There is a content request property for each web request which you can use in global.asax file.

http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.contentlength(v=vs.110).aspx

See following link in that they have explained what you need ie

// Set the 'Method' property of the 'Webrequest' to 'POST'.
        myHttpWebRequest.Method = "POST";
        Console.WriteLine ("\nPlease enter the data to be posted to the (http://www.contoso.com/codesnippets/next.asp) Uri :");

        // Create a new string object to POST data to the Url. 
        string inputData = Console.ReadLine ();


        string postData = "firstone=" + inputData;
        ASCIIEncoding encoding = new ASCIIEncoding ();
        byte[] byte1 = encoding.GetBytes (postData);

        // Set the content type of the data being posted.
        myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";

        // Set the content length of the string being posted.
        myHttpWebRequest.ContentLength = byte1.Length;

        Stream newStream = myHttpWebRequest.GetRequestStream ();

        newStream.Write (byte1, 0, byte1.Length);
        Console.WriteLine ("The value of 'ContentLength' property after sending the data is {0}",   myHttpWebRequest.ContentLength);

        // Close the Stream object.
        newStream.Close ();

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