Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# HttpWebRequest.GetResponseStream返回一个空字符串_C#_Httpwebrequest_Meta - Fatal编程技术网

C# HttpWebRequest.GetResponseStream返回一个空字符串

C# HttpWebRequest.GetResponseStream返回一个空字符串,c#,httpwebrequest,meta,C#,Httpwebrequest,Meta,我一直在尝试各种可能的方法,使用HttpWebRequest从一个页面下载并获取响应流,除了此页面之外,它在其他所有页面上都可以正常工作。正如您所看到的,返回的数据是一个HTML,但是它有一个我不擅长的元标记,但是我尝试得到这个块的结果是什么 {"error":4,"message":"Unsupported link format or unsupported hoster"} 似乎我不能,我尝试将GET内容类型指定为“text/json”,但没有任何帮助 下面是我在浏览器上打开页面时返回的

我一直在尝试各种可能的方法,使用
HttpWebRequest
从一个页面下载并获取响应流,除了此页面之外,它在其他所有页面上都可以正常工作。正如您所看到的,返回的数据是一个HTML,但是它有一个我不擅长的元标记,但是我尝试得到这个块的结果是什么

{"error":4,"message":"Unsupported link format or unsupported hoster"}
似乎我不能,我尝试将GET内容类型指定为“text/json”,但没有任何帮助

下面是我在浏览器上打开页面时返回的HTML内容,但在代码中它返回空字符串

    <html>
    <meta style="visibility: hidden !important; display: block !important; width: 0px !important; height: 0px !important; border-style: none !important;"></meta>
    <head></head>
    <body>
      <pre style="word-wrap: break-word; white-space: pre-wrap;">{"error":4,"message":"Unsupported link format or unsupported hoster"}
      </pre>
    </body>
    </html>

{“错误”:4,“消息”:“不支持的链接格式或不支持的主机”}
编辑:


我曾尝试在localhost上的一个页面中复制上述相同的html,并尝试获取其内容,但它确实起到了作用,IIS中是否存在一些可能阻止获取内容的限制?

尝试使用
WebRequest
类。您可以找到它的文档

页面中有以下示例:

// Create a request for the URL.        
WebRequest request = WebRequest.Create ("[your_url]");
// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse ();
// Display the status.
Console.WriteLine (response.StatusDescription);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream ();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);
// Read the content. 
string responseFromServer = reader.ReadToEnd ();
// Display the content.
Console.WriteLine (responseFromServer);
// Cleanup the streams and the response.
reader.Close ();
dataStream.Close ();
response.Close ();

这将在
控制台中打印该页面的HTML内容。

尝试使用
WebRequest
类。您可以找到它的文档

页面中有以下示例:

// Create a request for the URL.        
WebRequest request = WebRequest.Create ("[your_url]");
// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse ();
// Display the status.
Console.WriteLine (response.StatusDescription);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream ();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);
// Read the content. 
string responseFromServer = reader.ReadToEnd ();
// Display the content.
Console.WriteLine (responseFromServer);
// Cleanup the streams and the response.
reader.Close ();
dataStream.Close ();
response.Close ();

这将在
控制台中打印该页面的HTML内容。

您是否有证据表明问题出在客户端?更恰当的问题是:为什么服务器发送这种奇怪的内容?客户端只接收服务器发送的任何内容


我建议您调试服务器以发现问题,或者提出一个包含服务器端代码的新问题,并专门询问它。

您是否有证据表明问题出在客户端?更恰当的问题是:为什么服务器发送这种奇怪的内容?客户端只接收服务器发送的任何内容


我建议您调试服务器以找出,或者问一个包含服务器端代码的新问题,并具体询问它。

我也有同样的问题,原因是我以前将方法设置为
HEAD
,在以后的版本中需要解析主体。

我也有同样的问题,原因是我以前将方法设置为
HEAD
在以后的修订版中,需要解析正文。

在浏览器上打开该页时是否加载?如果是这样,请尝试复制您可能丢失的所有标题(推荐人、用户代理等)。如果尝试了,则无效。您是否正在尝试从直接下载站点(如NowDownload.eu或类似站点)自动下载?听起来可能是推荐人的问题。URL是什么?当你在浏览器上打开它时,页面会加载吗?如果是这样,请尝试复制您可能丢失的所有标题(推荐人、用户代理等)。如果尝试了,则无效。您是否正在尝试从直接下载站点(如NowDownload.eu或类似站点)自动下载?听起来可能是推荐人的问题。网址是什么?