locked
Set length of web response RRS feed

  • Question

  • User-1725027936 posted

    Hi all,

    I want to set length of web response that is returned by httpwebrequest get method.I dont want to get entire response because it creates network traffic.

     

    If anyone has any idea regarding this then please let me know.

    Thanks,

    Khushboo Nayak

    Friday, April 20, 2012 7:09 AM

Answers

  • User535082756 posted

    hi

    I think you can provide the maxlength in the web.config file like below

    <configuration> 
       
    <system.web>
           
    <httpRuntime maxRequestLength="32768" />

       
    </system.web>
    </configuration>
    hope it helps.thanks,
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 21, 2012 10:43 AM
  • User71929859 posted

    <httpRuntime
    maxRequestLength=
    "32768"
    />

    Hello,

    The above will limit the request size. Not the response size. 

    What kind of response you are getting? If you are getting a JSON response, you can limit it by adding the following to your web.config

    <configuration>
        <system.web.extensions>
            <scripting>
                <webServices>                                                
                   <jsonSerialization maxJsonLength="1000" />            
                </webServices>        
            </scripting>
        </system.web.extensions>
    </configuration>

    And I don't think limiting the response is a good idea. It could cut-off necessary information and may result in unexpected results.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 22, 2012 2:11 AM
  • User-1673382244 posted

    Hai

    Set length of web response

    I am assuming you are returning JSON?

    You can adjust the JSON response size in the web.config with:

    <configuration>
       
    <system.web.extensions>
           
    <scripting>  
                 
    <webServices>                                                  
                     
    <jsonSerialization maxJsonLength="1000000" />                
                 
    </webServices>
           
    </scripting>
       
    </system.web.extensions>
    </configuration>

    Doing a quick search, it looks like the default size is 102400.

    maxJsonLength Optional attribute.

    Configures the maximum length of the JSON string (the maximum number of UTF-8 characters).

    The default length is 102400.

    Set length of web Request

    The EAUpload component can processing uploads of up to 4 gigabytes. However, when using the product in .NET, it is important to configure the application settings to make sure ASP.NET doesn't block the large uploads before EAUpload can process them. 
    To work around this problem, increase the value of allowed request length.

    You can do that by following two ways:

    Method 1:
    EAUpload component provides a replacement of MaxRequestLength attribute of httpRuntime config section. If MaxRequestLength parameter of EAUpload environment is defined then request have allowed length that is specified by this parameter andmaxRequestLength parameter of httpRuntime configuration section is ignored. The specified value will take effect only for requests which are processed by EAUpload component. The value that is specified in maxRequestLength attribute will be actually for other requests. 

    Set the MaxRequestLength parameter value in the EAUpload configuration

    • Open the Web.config file in Notepad.
    • Increase the value of the MaxRequestLength parameter to avoid errors.
      <?xml version="1.0" encoding="utf-8" ?>
      <configuration>
      ...
         <EasyAlgo.EAUpload>
             <Environment
                 ...                
      
                 ExacutionTimeout="3600"
                 // Set maximum content length to 1GB.
                 MaxRequestLength="1048576"        
      
                 ...
             />
             <ErrorsProcessing
                  ...                   
              />
          </EasyAlgo.EAUpload>
      ... 
      </configuration>    
      
    • Save the Web.config file.

    Method 2:
    The maxRequestLength attribute exists under httpRequest in the Machine.config file. You can change these settings either in the Web.Config file or in the Machine.config file. The default value for the maximum request length is 4096 KB (4MB). ThemaxRequestLength attribute indicates the maximum file upload size supported by ASP.NET. This limit can be used to prevent denial of service attacks caused by users posting large files to the server. The size specified is in kilobytes. 

    Figure A: Set the maxRequestLength attribute value in the Web.config File

    • Open the Web.config file in Notepad.
    • Add the httpRuntime element in the system.web section as follows:
      <?xml version="1.0" encoding="utf-8" ?>
      <configuration>
      ...
       <system.web>
         <httpRuntime 
               executionTimeout="90"
               maxRequestLength="4096"/>
       </system.web>
      ... 
      </configuration>
      
    • Increase the value of the maxRequestLength attribute to avoid errors.
    • Save the Web.config file.

    Figure B: Set the maxRequestLength attribute value in the Machine.config File

    • Open the Machine.config file in Notepad. The Machine.config file is located in the %SystemRoot%\Microsoft.NET\Framework\%VersionNumber%\CONFIG\ directory.
    • In the Machine.config file, locate the httpRuntime element.
      <httpRuntime 
          executionTimeout="90"
          maxRequestLength="4096"
      	useFullyQualifiedRedirectUrl="false"
      	minFreeThreads="8"
      	minLocalRequestFreeThreads="4"
      	appRequestQueueLimit="100" />
      
    • Increase the value of the maxRequestLength attribute to avoid errors.
    • Save the Web.config file.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 22, 2012 4:57 AM

All replies

  • User535082756 posted

    hi

    I think you can provide the maxlength in the web.config file like below

    <configuration> 
       
    <system.web>
           
    <httpRuntime maxRequestLength="32768" />

       
    </system.web>
    </configuration>
    hope it helps.thanks,
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 21, 2012 10:43 AM
  • User71929859 posted

    <httpRuntime
    maxRequestLength=
    "32768"
    />

    Hello,

    The above will limit the request size. Not the response size. 

    What kind of response you are getting? If you are getting a JSON response, you can limit it by adding the following to your web.config

    <configuration>
        <system.web.extensions>
            <scripting>
                <webServices>                                                
                   <jsonSerialization maxJsonLength="1000" />            
                </webServices>        
            </scripting>
        </system.web.extensions>
    </configuration>

    And I don't think limiting the response is a good idea. It could cut-off necessary information and may result in unexpected results.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 22, 2012 2:11 AM
  • User-1673382244 posted

    Hai

    Set length of web response

    I am assuming you are returning JSON?

    You can adjust the JSON response size in the web.config with:

    <configuration>
       
    <system.web.extensions>
           
    <scripting>  
                 
    <webServices>                                                  
                     
    <jsonSerialization maxJsonLength="1000000" />                
                 
    </webServices>
           
    </scripting>
       
    </system.web.extensions>
    </configuration>

    Doing a quick search, it looks like the default size is 102400.

    maxJsonLength Optional attribute.

    Configures the maximum length of the JSON string (the maximum number of UTF-8 characters).

    The default length is 102400.

    Set length of web Request

    The EAUpload component can processing uploads of up to 4 gigabytes. However, when using the product in .NET, it is important to configure the application settings to make sure ASP.NET doesn't block the large uploads before EAUpload can process them. 
    To work around this problem, increase the value of allowed request length.

    You can do that by following two ways:

    Method 1:
    EAUpload component provides a replacement of MaxRequestLength attribute of httpRuntime config section. If MaxRequestLength parameter of EAUpload environment is defined then request have allowed length that is specified by this parameter andmaxRequestLength parameter of httpRuntime configuration section is ignored. The specified value will take effect only for requests which are processed by EAUpload component. The value that is specified in maxRequestLength attribute will be actually for other requests. 

    Set the MaxRequestLength parameter value in the EAUpload configuration

    • Open the Web.config file in Notepad.
    • Increase the value of the MaxRequestLength parameter to avoid errors.
      <?xml version="1.0" encoding="utf-8" ?>
      <configuration>
      ...
         <EasyAlgo.EAUpload>
             <Environment
                 ...                
      
                 ExacutionTimeout="3600"
                 // Set maximum content length to 1GB.
                 MaxRequestLength="1048576"        
      
                 ...
             />
             <ErrorsProcessing
                  ...                   
              />
          </EasyAlgo.EAUpload>
      ... 
      </configuration>    
      
    • Save the Web.config file.

    Method 2:
    The maxRequestLength attribute exists under httpRequest in the Machine.config file. You can change these settings either in the Web.Config file or in the Machine.config file. The default value for the maximum request length is 4096 KB (4MB). ThemaxRequestLength attribute indicates the maximum file upload size supported by ASP.NET. This limit can be used to prevent denial of service attacks caused by users posting large files to the server. The size specified is in kilobytes. 

    Figure A: Set the maxRequestLength attribute value in the Web.config File

    • Open the Web.config file in Notepad.
    • Add the httpRuntime element in the system.web section as follows:
      <?xml version="1.0" encoding="utf-8" ?>
      <configuration>
      ...
       <system.web>
         <httpRuntime 
               executionTimeout="90"
               maxRequestLength="4096"/>
       </system.web>
      ... 
      </configuration>
      
    • Increase the value of the maxRequestLength attribute to avoid errors.
    • Save the Web.config file.

    Figure B: Set the maxRequestLength attribute value in the Machine.config File

    • Open the Machine.config file in Notepad. The Machine.config file is located in the %SystemRoot%\Microsoft.NET\Framework\%VersionNumber%\CONFIG\ directory.
    • In the Machine.config file, locate the httpRuntime element.
      <httpRuntime 
          executionTimeout="90"
          maxRequestLength="4096"
      	useFullyQualifiedRedirectUrl="false"
      	minFreeThreads="8"
      	minLocalRequestFreeThreads="4"
      	appRequestQueueLimit="100" />
      
    • Increase the value of the maxRequestLength attribute to avoid errors.
    • Save the Web.config file.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 22, 2012 4:57 AM