Search code examples
c#visual-studio-2010httpwebrequestlinkedin-api

How to use webbrowsr control with Httpwebrequest?


I am using webbrowser control , and i get list of all the url of all the profiles from the search result.

After this is there any way that i use httpwebrequest to get the data from the urls?

I wanted to use the Linked in search profile api but that is very confusing. Also i tried using httpwebrequest but it takes me to the linkedin login page.

I was thinking of any way that as i signed in to linkedin using the webbrowser control maybe using that information of webbrowser and adding with my request to pretend to be logged in .

Any ideas? Please help


Solution

  • The HttpWebRequest sent you to the login page, because there isn´t the cookie with the validation. So, you'll can connect using WebBrowser control and get the cookie, then put the cookie in the webrequest

            webBrowser.Navigate(someUrl);
    
            ...
    
            CookieContainer cookies = new CookieContainer();
            foreach (string cookie in webBrowser.Document.Cookie.Split(';'))
            {
                string name = cookie.Split('=')[0];
                string value = cookie.Substring(name.Length + 1);
                string path = "/";
                string domain = "yourdomain.com";
                cookies.Add(new Cookie(name.Trim(), value.Trim(), path, domain));
            }
    
    
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.CookieContainer = cookies;
            ...