1

我一直在尝试所有可能的方法来下载从使用的页面获取响应流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>

编辑:

我已经尝试在本地主机上的页面中复制上面相同的 html 并尝试获取它的内容并且它确实有效,是否可能在 IIS 中存在一些可能阻止获取内容的限制?

4

3 回答 3

1

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

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

于 2013-01-27T14:17:53.287 回答
0

尝试使用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 ();

这将打印在Console该页面的 HTML 内容中。

于 2013-01-27T13:05:52.777 回答
0

我遇到了同样的问题,原因是我之前将方法设置为,HEAD并且在以后的修订中需要解析主体。

于 2013-05-02T10:20:26.360 回答