This topic has not yet been rated - Rate this topic

HttpRequest.SaveAs Method

Saves an HTTP request to disk.

Namespace:  System.Web
Assembly:  System.Web (in System.Web.dll)
public void SaveAs(
	string filename,
	bool includeHeaders
)

Parameters

filename
Type: System.String
The physical drive path.
includeHeaders
Type: System.Boolean
A Boolean value specifying whether an HTTP header should be saved to disk.
Exception Condition
HttpException

The RequireRootedSaveAsPath property of the HttpRuntimeSection is set to true but filename is not an absolute path.

Saving the request context to disk can be useful in debugging.

The following code example calls the SaveAs method when a page is loaded. The call specifies that the request be saved as a text file in a directory where the ASP.NET process identity has been granted write permissions, and that any header information included in the request is included in the file.


Request.SaveAs("c:\\temp\\HttpRequest.txt", true);


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
HttpRequest.SaveAs could be more useful
When I use includeHeadersfalse, i get zero bytes; when i use includeHeaderstrue, i get this (for a Samsung Corby Pro cellphone):

GET /home/contact/ HTTP/1.1
Accept: text/html, application/xml, image/vnd.wap.wbmp, image/png, image/jpeg, image/gif, image/bmp, application/vnd.wap.xhtml+xml, application/xhtml+xml, application/vnd.wap.multipart.mixed, multipart/mixed, text/vnd.wap.wml, application/vnd.wap.wmlc, application/vnd.oma.dd+xml, text/vnd.sun.j2me.app-descriptor, application/java-archive, */*
Accept-Charset: utf-8;q=1.0,iso-8859-1;q=0.6
Accept-Encoding: gzip,deflate
Accept-Language: en
Host: gerrylowryprogrammer.com
Referer: https://gerrylowryprogrammer.com/home/about/
User-Agent: SAMSUNG-GT-B5310R/B5310UXJB5 SHP/VPP/R5 Dolfin/1.5 Nextreaming SMM-MMS/1.2.0 profile/MIDP-2.1 configuration/CLDC-1.1
X-Wap-Proxy-Cookie: none
x-wap-profile: "http://wap.samsungmobile.com/uaprof/GT-B5310R.xml"


 to get more, it is necessary to write a custom save method.  Partial example of custom output:


Request.UserHostAddress:  76.68.47.29
Request.UserLanguages[0]:  en
Request.Url: https://gerrylowryprogrammer.com/home/contact/
Request.UrlReferrer: https://gerrylowryprogrammer.com/home/about/
Request.Browser.Browsers.CanSendMail:  True
Request.Browser.Browsers.Frames:  False
Request.Browser.Browsers.Tables:  False
Request.Browser.EcmaScriptVersion:  0.0
Request.Browser.Browsers.JavaApplets:  False
Request.Browser.Browsers.JScriptVersion:  0.0
Request.Browser.Browsers.W3CDomVersion:  0.0
Request.Browser.Browsers.MSDomVersion:  0.0
Request.Browser.Browsers.SupportsCss:  False

Additionally, i am able to get all of the information from Request.SaveAs("c:\\temp\\HttpRequest.txt", true);

Note:  a custom save allows you to save most, perhaps all, of the properties at http://msdn.microsoft.com/en-us/library/h55b6cak.aspx "HttpRequest Class", including nested properties like Request.Browser.EcmaScriptVersion.Major, et cetera.

Regards,
Gerry