首页 > 解决方案 > C# WebClient.DownloadString 不返回整个网页源

问题描述

WebClient.DownloadString用来获取网页的 Html 源代码,但我得到的回报是:

<html style="height:100%">
<head>
    <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport" content="initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
</head>

<body style="margin:0px;height:100%">
    <iframe id="main-iframe"
        src="/_Incapsula_Resource?CWUDNSAI=41&xinfo=9-19309783-0%20NNNY%20RT%281614802895891%2028%29%20q%280%20-1%20-1%20-1%29%20r%280%20-1%29%20B10%2814%2c0%2c0%29%20U18&incident_id=1309000160050658955-81390253115245577&edet=10&cinfo=0e000000b6ef&rpinfo=0"
        frameborder=0 width="100%" height="100%" marginheight="0px" marginwidth="0px">
        Request unsuccessful. Incapsula incident ID: 1309000160050658955-81390253115245577
    </iframe>
</body>

</html>

但是缺少页面的实际内容。我做错了什么?

标签: c#htmlwebclient

解决方案


您的 HTTP 请求不满足服务器的要求,因此 Incapsula 已将您标记为可疑用户。您发布的回复确实包含完整的网络回复文本。我会考虑确保您在请求中提供了足够的信息。

要检查以添加到您的 HTTP 请求的一些内容是用户代理、cookie 等标头。


推荐阅读