Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Updated 19-Jun-21 19:23pm
Comments
Sergey Alexandrovich Kryukov 15-Jun-11 22:10pm    
Is it ASP.NET? Tag it!
--SA

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.
 
Share this answer
 
Comments
vinayraju 15-Jun-11 11:37am    
Thanks for the information.........
NewWebDesigner 1-Jan-14 16:20pm    
Thank you.i am working on your answer...
Sergey Alexandrovich Kryukov 15-Jun-11 22:22pm    
That's correct, my 5.
See also my detailed solution on your #2.
--SA
C#
    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());

}
 
Share this answer
 
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
 
Share this answer
 
v2
Comments
RMSinha 28-Jul-15 6:49am    
Thanks i got it....
Sergey Alexandrovich Kryukov 28-Jul-15 7:41am    
You are welcome. So, will you accept the answer formally?
—SA
RMSinha 29-Jul-15 5:41am    
yes but some small changes i have done and finally i got it....
Sergey Alexandrovich Kryukov 29-Jul-15 10:18am    
Very good, but will you accept the answer?
—SA
I think, If the other site provide you webservice then you can use this webservice in your project by passing the required argumnet.
 
Share this answer
 
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

C#
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
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900