Download file programmatically from plumtree knowledge catalog

I am new to plumtree and I am trying to learn the Plumtree object model. I am trying to download a file from plumtree knowledge directory programmatically.

This is the code I am using:

IRemoteSession session = RemoteSessionFactory.GetExplicitLoginContext (new Uri (url), username, password);

IDocumentFolderManager DocFolderManager = session.GetDocumentFolderManager ();

IDocumentManager DocManager = session.GetDocumentManager ();

IObjectQuery FolderQuery = DocFolderManager.GetSubFolders (folderID);

IDocumentQuery DocQuery = DocManager.CreateQuery (FolderQuery.GetRow (i) .GetID ());

IObjectQuery DocumentQuery = DocQuery.Execute ();

Document IObjectQueryRow = DocumentQuery.GetRow (1);

IDocumentProperties _docProperties = DocManager.QueryDocumentProperties (document.GetID ());

string docUrl = _docProperties.GetStringValue (5);

WebClient webclient = new WebClient ();

webclient.Credentials = new System.Net.NetworkCredential (username, password, "");

webclient.Credentials = CredentialCache.DefaultCredentials;

webclient.DownloadFile (docUrl, "c: \ 1");

But there seems to be some problem with my session creation code, because instead of downloading the actual file, this code loads the Plumtree login page into my filesystem.

Can someone please tell me what I am doing here? There must be something I'm missing

+1


source to share


1 answer


The problem is that your webclient instance doesn't know how to authenticate to the plumtree server. new NetowrkCredential () or CredentialCache.DefaultCredentials works in simple cases, but obviously not in this.

Plumtree uses a cookie, or (more likely) a specific login token, which is obtained by calling GetExplicitLoginContext () and then dispatched along with all subsequent requests in that session.



You can potentially spoof this "sent along with all subsequent requests" with the WebClient, but you will need to learn more technical details about how Plumtree servers authenticate clients. You can find some of this information using Fiddler , but the easiest way is to find the API that plumtree offers to download files that were previously uploaded to Plumtree.

Another (hacky) way to approach this is to spoof the browser client. Make your request above, then parse the HTML, pull out the url of the login form action, and then slip in an HttpWebRequest call that looks like a real client filling out the login form. You will need to use a CookieContainer to make sure the cookies are sent, make sure the headers are correct, etc. See http://channel9.msdn.com/forums/TechOff/162017-Using-WebClient-to-enter-Form-based-Auth-system-How/ for more information.

+1


source







All Articles