There is no built-in way, but you can simply use the GetResponseStream method to get the response stream and save it to a file.
Example:
WebRequest myRequest = WebRequest.Create("http://www.example.com"); using (WebResponse myResponse = myRequest.GetResponse()) using (StreamReader reader = new StreamReader(myResponse.GetResponseStream())) {
However, you can wrap it in an extension method
WebRequest myRequest = WebRequest.Create("http://www.example.com"); using (WebResponse myResponse = myRequest.GetResponse()) { myResponse.SaveAs(...) }
...
public static class WebResponseExtensions { public static void SaveAs(this WebResponse response, string filePath) { using (StreamReader reader = new StreamReader(response.GetResponseStream())) { File.AppendAllText(filePath, myResponse.Headers.ToString()); File.AppendAllText(filePath, reader.ReadToEnd()); } } }
sloth source share