Example on how to post a topic using the SharpLeech Engine. You can get the .dll by downloading SharpLeech and add a reference to it in your project.
You'll need these namespaces:
The example (read the comments):
There are a lot more handy classes and whatnot in SLE. Even the classes that were used here have a lot more handy properties, functions, etc. You have access to everything that makes SharpLeech tick .
You'll need these namespaces:
PHP:
using System;
using System.Net;
using Hyperz.SharpLeech.Engine;
using Hyperz.SharpLeech.Engine.Net;
PHP:
// our login details
string username = "name";
string password = "****";
// the topic that we will post.
// The last argument (2) is the forums section id
SiteTopic topic = new SiteTopic("The title", "the [b]content[/b]", 2);
// Setup the object that we will use to post the topic
SiteType forum = DefaultSiteTypes.ByName("IP.Board 3.x.x").CreateInstance();
// forum url
forum.BaseUrl = "http://path.to/forum";
// Attach an event handler to the login event
// We'll use lambda expressions - quick 'n easy
forum.Login += (sender, e) =>
{
// did we actually login?
if (e.LoggedIn)
{
// yes we did
// now collect the data needed to create a new topic
forum.MakeReady(topic.SectionId);
}
};
// Now attach an event handler to the ReadyChanged event
// This event fires when all needed 'new topic' data has been collected
forum.ReadyChanged += (sender, e) =>
{
// are we really ready?
// collecting the data can fail so we need to double check
if (forum.IsReady)
{
// ok we are!
// now we can post our topic
// first create our http request
HttpWebRequest req = forum.CreateTopic(topic);
// and now make the request
HttpResult result = Http.Request(req);
// if you want you can check if there were errors
if (result.HasError)
{
// oh noes
// we can log the error if we want:
ErrorLog.LogException(result.Error);
}
// you can also grab the response data
string responseHtml = result.Data;
}
};
// with both those events setup we can now actually login
// as soon as we do all needed data will get collected and the topic posted
forum.LoginUser(username, password);
// all done!