Sending POST parameters via HTTP to a server in C#

December 21, 2009 by paulhenry · Comments Off
Filed under: C# Tutorials, Tutorials 

Here is a C# Method for sending data to a server via POST.

You would call this method like this:
get_post_response("http://somesite/", "email=email&password=password")

If any of the characters in the params contain special characters (Such as $, #, @) you must call HttpUtility.UrlEncode() on each param or on the entire param string. Here is how you do that: http://www.vcskicks.com/encode-url.php

public static string get_post_response(string page_url, string page_params) {
  var request = (HttpWebRequest)HttpWebRequest.Create(page_url);
  request.CookieContainer = new CookieContainer();
  request.CookieContainer.Add(session);
  request.ContentType = "application/x-www-form-urlencoded";
  request.Method = "POST";
  byte[] bytes = Encoding.ASCII.GetBytes(page_params);
  request.ContentLength = bytes.Length;
  using (Stream os = request.GetRequestStream()) {
     os.Write(bytes, 0, bytes.Length);
  }

  var resp = request.GetResponse();

  CookieContainer cookieJar = new CookieContainer();

  session = cookieJar.GetCookies(request.RequestUri);

  Stream respStream = resp.GetResponseStream();

  byte[] buffer = new byte[1024];
  string text = "";

  while (Convert.ToBoolean(respStream.Read(buffer, 0, buffer.Length)))
     text += Encoding.ASCII.GetString(buffer).Trim('\0');

  return text;
}

Enjoy!

Say thank you to our troops!

December 10, 2009 by paulhenry · Comments Off
Filed under: Uncategorized 

How to install Adobe Flash 10 on Slackware 13 for Firefox

December 7, 2009 by paulhenry · Comments Off
Filed under: Linux Tutorials 

The installation of adobe flash on Slackware is quite a simple process actually. It requires 4 steps.

First, open a terminal then type su to get a root shell.

Next run the following command to get the latest version of adobe flash 10 from adobe.
root@paulhenry-laptop:~# wget http://fpdownload.macromedia.com/get/flashplayer/current/install_flash_player_10_linux.tar.gz

Next uncompress the file you just downloaded.
root@paulhenry-laptop:~# tar -zxvf install_flash_player_10_linux.tar.gz

Then simply copy the uncompressed library file to the /plugins directory of firefox.
root@paulhenry-laptop:~# cp libflashplayer.so /usr/lib/firefox/plugins/

Restart (or start) firefox and look in Tools->Addons->Plugins and Shockwave flash should be installed!

Feel free to email me at paulhenry@mphwebsystems.com if you have any problems.

New forums!

August 12, 2009 by paulhenry · Comments Off
Filed under: Updates 

Check out our new forms! Feel free to join up and post!

http://forums.mphwebsystems.com/

Also check out our project management suite: http://project.mphwebsystems.com/

If you would like an account on the project management suite, please email me at paulhenry@mhpwebsystems.com

Scoring?

August 12, 2009 by paulhenry · Comments Off
Filed under: Competition Mangement System 

Alright, so one of the major things that CMS will accomplish is the automatic scoring of a registered competition. How will CMS do this?

First of all, we can lay down some basic rules on how we get the total score for each team.

First: A team’s total score is the sum of all rounds by that team. This tells us that for each team, their competition score is the sum of the total score for all rounds played by that team.

Second: A round has one or more actions.

Third: Every competition has a registered number of actions per round.

Fourth: Each action contributes to each round’s total score.

All we really need to do to find out scores is just to define actions, and those actions will make up rounds, and those rounds will make up a team’s score.

Now we just need to lay down some rules about how special cases, like ties are handled. I am thinking an additional round will be added. Anything you all would suggest?

New Main Website design

July 25, 2009 by paulhenry · Comments Off
Filed under: Updates 

Alight, so over the past few weeks, I have been monitoring the bandwidth usage for both blog.mphwebsystems.com and the main site, mphwebsystems.com and noticed one very interesting thing. There have been approximately 1,100 hits on the main site, and there have been 3,000 hits on the blog. Now, the really interesting part is the bandwidth used by both. The main site, with 1,100 hits, used 13 MB. The blog, with 3,000 hits, used 10 MB. The theme I have used for the main site is extremely heavy, with 1600 lines of CSS, and about 20 images. The theme used for the blog is very very light and simple, thus the lower bandwidth usage. Now what this shows, is that it really makes a big difference how your website is designed.

Because of this difference, I went ahead and decided to redesign the main site. The new design has 3 images, and 251 lines of CSS, much lighter and simpler. I think the hardest part of web development is finding the balance between size and “shinyness”.

CMS Database Design

July 22, 2009 by paulhenry · 1 Comment
Filed under: Developement Projects 

Hi all, it has been a while since I posted something new. I have been on a trip fixing up a house, but hey! I have been getting lots of programming in during my free time.

I think I have pretty much finalized the database design for the Competition Management System that is under development. Here is an image:
cms_db.jpg

Everything grouped under Registered Competition Tables basically all depends on a single competition entry into the Competitions table. Notice the separate accounts table, every type of account, except for admins, is linked from that table to either a Competition entry, a school entry or a team entry via the links table. This also allows for multiple links from a single account.

CMS Developement has begun!

July 10, 2009 by paulhenry · Comments Off
Filed under: Developement Projects 

I have started work on CMS (Competition Management System). Its going to be a cool system! I am implementing Object Orientation into the PHP, like say you call a method and send that method a SQL script, it executes that script, and hands you back an object. It just puts another abstraction layer of the database communication.

If you would like to preview this system, while it is being developed, add a comment below, and I will get back with you! :)

Chat bot functions

June 28, 2009 by paulhenry · 1 Comment
Filed under: Developement Projects 

So in this post, I would like to give you a description of each function in the chat bot, and the way each function works.

First we will go over the 2 simple functions.
!say : This function causes the bot to print out whatever is in message, like it is talking in the channel, if you where to type “/msg kk !say “, the bot would just print the message out to the channel, but your message would not appear in the channel.
!is : This is the equivalent of /is , it is like a status update.

Now we have about 6 functions that allow conversion between value representation.
!decbin : This simply converts number to a binary representation, like the binary representation of 3 is 11.
!dechex : This gives you the hexadecimal representation of number.
!hexdec : Outputs the decimal equivalent of number.
!hexbin : Gives you the binary representation of number.
!bindec : Gives you the decimal representation of number.
!binhex : Gives you the hexadecimal representation of number.

Now, here are the 2 “coolest” functions.
!calc : This is a fascinating function. It will evaluate expression as a mathematical expression. How does is it do it? The bot will actually take expression, processes the text, and then actually puts it into C# code, compiles the code, then runs the code natively, on the host machine, instead of just the classic string parsing method. This means that you can put your own C# code into it. while loops, if statements, etc. Now it does have a timer, where if it has been running longer than 10 seconds, then it will kill itself, as that normally means that it is in an infinite loop. Here are the list of functions you can have in the expression

  • Abs(number): Gives the absolute value of number.
  • Acos(number): Returns the angle whose cosine is the specified number.
  • Asin(number): Returns the angle whose sine is the specified number.
  • Atan(number): Returns the angle whose tangent is the specified number.
  • Atan2(number1, number2): Returns the angle whose tangent is the quotient of two specified numbers.
  • BigMul(number1, number2): Returns the angle whose tangent is the quotient of two specified numbers.
  • Ceiling(number): Overloaded. Returns the smallest integer greater than or equal to the specified number.
  • Cos(number): Returns the cosine of the specified angle.
  • Cosh(number): Returns the hyperbolic cosine of the specified angle.
  • Exp(number, power): Returns e raised to the specified power.
  • Floor(number): Returns the largest integer less than or equal to the specified number.
  • IEEERemainder(number1, number2): Returns the remainder resulting from the division of a specified number by another specified number.
  • Log(number): Returns the logarithm of a specified number.
  • Log10(number): Returns the base 10 logarithm of a specified number.
  • Max(number1, number2): Returns the larger of two specified numbers.
  • Min(number1, number2): Returns the smaller of two numbers.
  • Pow(number, power): Returns a specified number raised to the specified power.
  • Round(number, [decimalplaces]): Rounds a value to the nearest integer or specified number of decimal places.
  • Sign(number): Returns a value indicating the sign of a number.
  • Sin(number): Returns the sine of the specified angle.
  • Sinh(number): Returns the hyperbolic sine of the specified angle.
  • Sqrt(number): Returns the square root of a specified number.
  • Tan(number): Returns the tangent of the specified angle.
  • Tanh(number): Returns the hyperbolic tangent of the specified angle.

These are the values you can use.

  • E: Represents the natural logarithmic base, specified by the constant, e.
  • PI: Represents the ratio of the circumference of a circle to its diameter, specified by the constant, π.

!factor : This simply takes number, and outputs the prime factorization of that number. Now in order to do that, it must calculate the number to see if it is prime, and that can take a very very long time. I have actually implemented some caching, where it will cache prime numbers. The caching can decrease the time it takes to calculate the prime factorization by nearly half!! It is really simple really…

That is all the current functions for right now, I will definitely add more functions, including an actually chat engine. Stay tuned! :)

New Home page feature

June 27, 2009 by paulhenry · Comments Off
Filed under: Uncategorized 

The highlights section on the http://mphwebsystems.com/ now displays the last two blog posts. RSS feeds FTW!! :)

Next Page »