【问题标题】:fetch data from URL in ASP.NET从 ASP.NET 中的 URL 获取数据
【发布时间】:2012-04-17 22:31:28
【问题描述】:

我是 asp.net 的新手,

我想从 asp.net 上的 url 获取数据。 & 需要将数据存储到字符串中。

如果假设这是我的 URL,那么我想以字符串形式获取此 URL 数据,

http://www.islamicfinder.org/prayer_service.php?country=bahrain&city=manama&state=02&zipcode=&latitude=26.2361&longitude=50.5831&timezone=3.00&HanfiShafi=1&pmethod=4&fajrTwilight1=&fajrTwilight2=&ishaTwilight=0&ishaInterval=0&dhuhrInterval=1&maghribInterval=1&dayLight=0&simpleFormat=xml

【问题讨论】:

    标签: asp.net .net string visual-studio-2010 url


    【解决方案1】:

    试试这个

    string url = "http://www.islamicfinder.org/prayer_service.php?country=bahrain&city=manama&state=02&zipcode=&latitude=26.2361&longitude=50.5831&timezone=3.00&HanfiShafi=1&pmethod=4&fajrTwilight1=&fajrTwilight2=&ishaTwilight=0&ishaInterval=0&dhuhrInterval=1&maghribInterval=1&dayLight=0&simpleFormat=xml";
                var webClient = new WebClient();
                string data = webClient.DownloadString(url);
    

    【讨论】:

    • 我想将这些数据存储到我的表中,我应该怎么做?
    • @krunal 这取决于很多事情。你用的是什么数据库?什么数据访问技术?
    • 我没有使用任何数据库,我只想将这些数据存储在我的 HTML TABLE 中。我应该怎么做?
    • @krunal 您需要提供有关表格格式的更多信息。表格是否已经在页面上?请编辑您的问题以使我能够准确回答或创建一个新问题并将链接粘贴到此处。
    • 我想从这个 url "ipad.idealake.com/default.aspx?id=G" 获取数据,我想在我的 HTML 表中显示这个数据.. 我试过这个 ("geekswithblogs.net/dotNETvinz/archive/2009/06/24/…) 代码,但它显示我的错误表格1.
    【解决方案2】:

    WebClient 对这类事情很有用(scartag 的回答证明了这一点的简单性),但对于更高级的选项,您应该查看底层的 WebRequest 类:

    // Create a request for the URL.        
    WebRequest request = WebRequest.Create ("http://www.contoso.com/default.html");
    
    // 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 ();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-26
      • 1970-01-01
      • 2020-07-27
      • 2013-05-06
      • 2019-01-30
      • 2012-05-10
      • 2011-01-16
      • 2010-10-06
      相关资源
      最近更新 更多