C# Regular Expression links

by pietman 14. May 2012 07:03

http://oreilly.com/windows/archive/csharp-regular-expressions.html

http://www.mikesdotnetting.com/Article/46/CSharp-Regular-Expressions-Cheat-Sheet

TESTER

simple example:

 

const string LocalLinkRegex = @"href=""\/livechess\/game\.html\?id\=(?<GameId>[0-9]*)""";
var R2 = new Regex(LocalLinkRegex, RegexOptions.ExplicitCapture);
var Matches2 = R2.Matches(result);

string href;

string FirstGameIdValue = Matches2[0].Groups["GameId"].Value;

/*
this will find:  /livechess/game.html?id=123456789
and return: 123456789  (which is token: GameId)
*/



Tags:

very useful commands

by pietman 12. May 2012 16:51
File.WriteAllText("dump.html", response);

Tags:

logging into a website the c# way (cookies)

by pietman 12. May 2012 16:46
var cookies = new CookieContainer();
ServicePointManager.Expect100Continue = false;

var request = (HttpWebRequest)WebRequest.Create("http://www.hotfile.com/login.php");
request.CookieContainer = cookies;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
using (var requestStream = request.GetRequestStream())
using (var writer = new StreamWriter(requestStream))
{
    writer.Write("user=XX&pass=XX&returnto=/");
}

using (var responseStream = request.GetResponse().GetResponseStream())
using (var reader = new StreamReader(responseStream))
{
    var result = reader.ReadToEnd();
    Console.WriteLine(result);
}

Tags:

c#

About ...

pietman celliersPietman Celliers
Bitlink  Ltd
bitlinkit.com