I got two ways to grab the address book from any website....
1. By using DownloadData and UploadValues Methods of WebClient Class
The basic algorithm is:
- Create
WebClient
class object to get the methods for sending and receiving data from a resource identified by a URL. - Set the user agent info in the header and set the proxy setting.
- Download the login page.
- By the Regular Expression, extract the desired name value collection which we have to send with login information, for example, user name, password, etc. to get the address book.
- Again, set the header information such as user agent, etc.
- Upload the page and get the cookies information.
- Download the address book page.
- Create the name value collection.
- Set the header information such as cookies info, user agent, etc.
- Upload the page with name value collection - it will return address book in byte array format.
Please refer to the attached code file: Contact_Importer_.aspx.cs.zip.
2. By using the HTTPWebRequest and HTTPWebResponse HTTP Classes of the .NET Framework
The basic algorithm is:
- The first step for getting a web page is to instantiate an
HttpWebRequest
object. This occurs when invoking the static Create()
method of the WebRequest
class. - Set request header fields and user credentials.
- Get response from the server in
stream
object and add user credential information with it. - Send further Request by sending cookie within the request.
- Again use
create()
method to open address book page. - Get the response by sending cookie information with the request, it will return address book page in byte array format.
Please refer to the attached code file: Contact_Page_Importer.cs.zip.
History
- 27th February, 2008: Initial version