简体   繁体   English

C# 下载 HTML 页面到字符串 asp.net

[英]C# download HTML page to string asp.net

I'm trying to download a aspx page's html from an another page, using the following code:我正在尝试使用以下代码从另一个页面下载 aspx 页面的 html:

  WebClient webClient = new WebClient();
             String CompleteReport = webClient.DownloadString(new System.Uri(reportURL));

however the HTML that is returned contains the markup similar to the following:但是,返回的 HTML 包含类似于以下内容的标记:

"\r\n\r\n<!DOCTYPE html>\r\n\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n<head><meta charset=\"utf-8\" 

what should i do to download a string without these escape sequences.我应该怎么做才能下载没有这些转义序列的字符串。

Thank You!谢谢你!

The string doesn't actually contain those sequences.该字符串实际上并不包含这些序列。 It contains the characters that they represent (actual newline and linefeed characters).它包含它们所代表的字符(实际的换行符和换行符)。

You are probably viewing the string in a debugger and the debugger is adding those sequences for you.您可能正在调试器中查看字符串,并且调试器正在为您添加这些序列。 If you dump it to a file and read it in notepad they won't be there.如果您将其转储到文件中并在记事本中阅读,它们将不存在。

See also this answer .另请参阅此答案 If you add ,nq to the variable name in the watch window, the escape sequences will go away.如果在监视窗口中将,nq添加到变量名称,转义序列将消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM