问题
I'm trying to get the source code of https://www.americasarmy.com/soldier/1309069
using the following code:
using (WebClient client = new WebClient())
{
ViewBag.htmlCode = client.DownloadString("https://www.americasarmy.com/soldier/1309069");
}
回答1:
As it returns 404, the source string will be in the WebException.Response :
try
{
client.DownloadString("https://www.americasarmy.com/soldier/1309069");
}
catch (WebException webex)
{
using (var streamReader = new StreamReader(webex.Response.GetResponseStream()))
{
var htmlCode = streamReader.ReadToEnd();
}
}
来源:https://stackoverflow.com/questions/42398465/additional-information-the-remote-server-returned-an-error-404-not-found-mv