Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0
Hi,
I have a doubt I am developing a website i need the details from another site how can i get that.........
 
For Example:if my user what to check the details of a train i want to get the details from another site is this possible..If possible how can i get it..
 
Train No:..........(user specified)
 
Details of the train(details should come from another site to my site)
 
........................
............................
.............................
 
I have heard that this is possible my HTTP Request and HTTP Response..
 
Please tell the how can we use that and get the details or is ther any other method..
 

Thanks in advance...
Posted 15-Jun-11 5:10am
Comments
SAKryukov at 15-Jun-11 22:10pm
   
Is it ASP.NET? Tag it!
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

There are two ways to do this:
- If the site you want to take data from has a public web service API, use that. Ask the owner of the site if there isn't one advertised, they may have one you can use.
- If not, you can 'visit' the site with WebRequests and parse the information you want out of the result. Depending on the makeup of the site, this can be trivial or almost impossible (for example if the information is retrieved dynamically through Javascript and you don't have access to the feed yourself). Before doing this, check the terms of use of the site (or ask the owner), because it adds significant load to their site and many people don't like you doing it.
  Permalink  
Comments
vinayraju at 15-Jun-11 11:37am
   
Thanks for the information.........
somayeh151 at 1-Jan-14 16:20pm
   
Thank you.i am working on your answer...
SAKryukov at 15-Jun-11 22:22pm
   
That's correct, my 5.
See also my detailed solution on your #2.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

If you have heard of HttpWebRequest, why not using it? This is a correct way.
 
Compile-time type should be System.Net.WebRequest though, as the run-time type is defined by the Uri parameter passed to its factory method System.Net.WebRequest.WebRequest.Create.
 
See the code sample here: http://msdn.microsoft.com/en-us/library/system.net.webrequest.aspx[^], see also http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx[^].
 
See these articles:
How to use HttpWebRequest and HttpWebResponse in .NET[^],
HttpWebRequest/Response in a Nutshell - Part 1[^].
 
—SA
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

		StringBuilder sb  = new StringBuilder();
		byte[]        buf = new byte[8192];
 
		HttpWebRequest  request  = (HttpWebRequest)
			WebRequest.Create("http://www.shinestars.tk");
		HttpWebResponse response = (HttpWebResponse)
			request.GetResponse();
		Stream resStream = response.GetResponseStream();
		string tempString = null;
		int    count      = 0;
 
		do
		{
			count = resStream.Read(buf, 0, buf.Length);
 
			if (count != 0)
			{
 
			tempString = Encoding.ASCII.GetString(buf,0,count);
				// continue building the string
				sb.Append(tempString);
			}
		}
		while (count > 0); // any more data to read?
	  Console.WriteLine(sb.ToString());
     
	}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

I think, If the other site provide you webservice then you can use this webservice in your project by passing the required argumnet.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

you can do it. first you record process by httpwatch or in IE9 (Press F12) and get the details of url, refer, accept, request body and resposnse. than in asp.net use these information by using system.net here is simple example
 
public string siteOutput(string url,string Method,string refer,string ContentType,string reqBody)
{ 
        HttpWebRequest request;
        HttpWebResponse response;
CookieContainer coo = new CookieContainer();
 
request.CookieContainer = coo;
                request = (HttpWebRequest)WebRequest.Create(url);
                request.Method =Method; //"POST";
                request.Referer =refer; //"http://www.YourSite";

                request.ContentType = ContentType; //"application/x-www-form-urlencoded";
                //request.Headers.Add("Cookie", c0 + ";" + c1);
                
                poststring =reqBody; //"loginId=" + loginId + "&email=" + email + "&unitName=" + unitName + "&designation=" + designation + "&firstName=" + firstName + "&middleName=&lastName=singh&phoneNumber=&mobileNumber=";

                using (Stream sm = request.GetRequestStream())
                {
                    byte[] databyte = System.Text.Encoding.ASCII.GetBytes(poststring);
                    sm.Write(databyte, 0, (int)databyte.Length);
                }
 
                response = (HttpWebResponse)request.GetResponse();
                string strPageOutPut = new StreamReader(response.GetResponseStream()).ReadToEnd();
return strPageOutPut
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 445
1 CHill60 410
2 Sergey Alexandrovich Kryukov 354
3 BillWoodruff 190
4 PIEBALDconsult 160


Advertise | Privacy | Mobile
Web03 | 2.8.141015.1 | Last Updated 21 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100