login to a different website from my website, and then requesting a new URL

Last post 05-09-2008 10:35 AM by ralph.varjabedian. 7 replies.

Sort Posts:

  • login to a different website from my website, and then requesting a new URL

    05-09-2008, 3:47 AM
    • Member
      point Member
    • BullFrogDude
    • Member since 04-30-2008, 3:58 PM
    • Posts 9

    Hello~

          I want to build a web service that connects to an existing application and grabs the ID used on another site (I store this data in my application) then have it login to the other website and then request a specific URL.  I would like to use CSharp if I need to do anything that is not just ASP.

    Any help is welcomed!
     

    Thanks,
     

  • Re: login to a different website from my website, and then requesting a new URL

    05-09-2008, 4:43 AM

    This other website that you want to connect to, is it a webservice or a normal website that you want to logon to programatically?

     

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    My Blog
    If you get the answer to your question, please mark it as the answer.
  • Re: login to a different website from my website, and then requesting a new URL

    05-09-2008, 4:48 AM
    • Member
      point Member
    • BullFrogDude
    • Member since 04-30-2008, 3:58 PM
    • Posts 9

     It has a web service, but I want to login programmatically.

     

  • Re: login to a different website from my website, and then requesting a new URL

    05-09-2008, 5:03 AM

    Can't you log in from some methods provided from the webservice itself?

    Or do you have to login from the main website through html pages?

    Please explain more in detail how exactly can you log in to the website so that I can help you better.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    My Blog
    If you get the answer to your question, please mark it as the answer.
  • Re: login to a different website from my website, and then requesting a new URL

    05-09-2008, 5:17 AM
    • Member
      point Member
    • BullFrogDude
    • Member since 04-30-2008, 3:58 PM
    • Posts 9

    ok, more info.....

    My Application is a CRM system.

    My web service is going to be loaded into an IFrame on a contact tab of the CRM application.

    The site I want to login to is facebook.  (they have a great API etc, but I do not want this to be a facebook application unless it has to be.) 

     
    desired functions...

    When opened it will login to facebook

    request the facebook friendID from CRM (It will be entered in the CRM system already.)

    Request the friends profile from facebook with the friendID (the person requested is already a friend so I have view rights once logged in) 

     

    Thanks,

    BullFrogDude 


     

     

  • Re: login to a different website from my website, and then requesting a new URL

    05-09-2008, 5:36 AM

    I see, then logging in to facebook must be done via Its APIs, I have never used the APIs for facebook so I am afriad I won't be able to help you in this aspect.

    Best of luck.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    My Blog
    If you get the answer to your question, please mark it as the answer.
  • Re: login to a different website from my website, and then requesting a new URL

    05-09-2008, 5:40 AM
    • Member
      point Member
    • BullFrogDude
    • Member since 04-30-2008, 3:58 PM
    • Posts 9

    I understand that, but do you know of a guide for how to do this with a site that does not have any API's? 

     

  • Re: login to a different website from my website, and then requesting a new URL

    05-09-2008, 10:35 AM
    Answer
     there is no one way. and it is not straight forward.

    You have to use the HttpWebRequest class to programatically call the pages and possibly send query string or post data.

    If the site you are trying to log to is simple and easy and can be done with a simple <form> to post the data then chances are you can do it easily but if the site you are trying to log in is not using a simple form, maybe using some dynamically generated hidden fields or hashes or CAPTCHA or using some javascript code then you might not be able to do it at all. It is analyzed per site.

    Also you might need to get a page, parse it, and from its <input> values prepare post data to send it back, in this case you have to retain the cookies as well inside a cookie container and you have to add all the proper headers yourself. As I said this is not not straight forward, more often than not it is a headache. Here is a quick code to get you started if your lucky :) But my guess is you will not be able to do it for facebook, it is a complicated site.

            //post data (if you have any) should be in the query form
            // variable=value&variable1=value1& ...

            public static string GetPageContents(string url, string postData)
            {
                HttpWebResponse response = null;
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
                //request.UserAgent = userAgent; // if you want a user agent to be added
                //request.CookieContainer = cookies; // if you want a cookie container to hold the values of the cookies


                if (postData != null)
                {
                    ASCIIEncoding encoding1 = new ASCIIEncoding();

                    byte[] buffer = encoding1.GetBytes(postData);
                    request.Method = "POST";
                    request.ContentLength = buffer.Length;
                    request.ContentType = "application/x-www-form-urlencoded";

                    Stream stream = request.GetRequestStream();
                    stream.Write(buffer, 0, buffer.Length);
                    stream.Close();
                }

                Stream responseStream = null;

                try
                {
                    response = (HttpWebResponse) request.GetResponse();
                    responseStream = response.GetResponseStream();
                }
                catch (WebException ex)
                {
                    if (ex.Response != null && request.HaveResponse &&
                        ex.Status == WebExceptionStatus.ProtocolError)
                    {
                        responseStream = ex.Response.GetResponseStream();
                    }
                    else
                        throw
    ex;
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                StreamReader reader = new StreamReader(responseStream);
                string resultOfPage = reader.ReadToEnd();
                reader.Close();
                if (response != null)
                    response.Close();
                return resultOfPage;
            }

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    My Blog
    If you get the answer to your question, please mark it as the answer.
Page 1 of 1 (8 items)