如何在 asp.net 中更改标头值中的内容长度

本文关键字:asp net | 更新日期: 2023-09-27 18:30:52

我需要将 asp.net aspx 页的标头值的内容长度属性设置为 100,但客户端说他们可以将其接收为 20。但我在这方面很陌生。那么,我想知道如何更改 aspx 页面的内容长度?由于 aspx 页在 html 中实际上是空白的,因此只有.cs文件具有处理传入请求字符串的代码。但是客户抱怨说,他们已经阅读了内容=长度只有20,所以它最多只能读取20个字符,而不是在那之后。请帮我解决这个问题。我的aspx页面只有这一行:

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

如何在 asp.net 中更改标头值中的内容长度

每个 Web 请求都有一个内容请求属性,您可以在 global.asax 文件中使用该属性。

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

请参阅以下链接,因为他们已经解释了您的需求,即

// 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 ();