【问题标题】:extract header info from a get request on a remote URL in asp.net?从asp.net 中远程URL 上的get 请求中提取标头信息?
【发布时间】:2010-09-10 03:01:30
【问题描述】:

我想对远程 URL 执行 get 请求,然后提取返回的标头。

感谢您的帮助!

【问题讨论】:

    标签: asp.net http httpwebrequest http-headers httpwebresponse


    【解决方案1】:

    作为MSDN Documentation

    如果您提出任何要求,POST 或 GET 喜欢:

    // Creates an HttpWebRequest for the specified URL. 
    HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); 
    

    您将始终得到一个 Response 对象,例如:

    // Sends the HttpWebRequest and waits for response.
    HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); 
    

    您可以通过以下方式获取所有标题:

    myHttpWebResponse.Headers
    

    然后像这样遍历它们:

    for(int i=0; i < myHttpWebResponse.Headers.Count; ++i)  
        Console.WriteLine("\nHeader Name:{0}, Value:1}",myHttpWebResponse.Headers.Keys[i],myHttpWebResponse.Headers[i]); 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-05
      • 2014-09-08
      • 1970-01-01
      • 2023-02-10
      • 2022-11-17
      • 1970-01-01
      • 2019-09-10
      • 2011-06-06
      相关资源
      最近更新 更多