2012-04-04 3 views
3

Я новичок в asp.net,извлекать данные из URL-адреса в ASP.NET

ı хочу получить данные с url на asp.net. & нужны данные для хранения в строке.

, если предположить, что это мой URL THN я хочу, чтобы принести этот 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 

ответ

5

Попробуйте

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); 
+0

Я хочу хранить эти данные в своей таблице, как мне это сделать? – Krunal

+0

Создайте эту таблицу и используйте в ней конструкцию Entity Framework –

+1

@krunal Это зависит от множества вещей. Какую базу данных вы используете? какая технология доступа к данным? – scartag

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(); 
Смежные вопросы