It's unfortunate that when we feel a storm, we can roll ourselves over 'cause we're uncomfortable, oh well the devil makes us sin, but we like it when we're spinning, in his grin...

Τρίτη 24 Ιουλίου 2012

php and vb.net example



In this tutorial I will show you how you can make a vb.net application communicate with a php one.
Supposing you have php and web server installed in your computer, I will show you how to do that in another tutorial, I can start.

First of all I just make a simple php page containing the following code:
<?php
if (isset($_GET['password'])) {
   $password = $_GET['password'];
 
   if ($password == 'somepass123')
     echo 'You won!';
   else
     echo 'Invalid password!';
}
?>
So now we have our simple php which actually checks for a get request with a parameter called password and if we set it to be "somepass123" (without the quotes) then it produces a message saying You won! in any other situation it just produces a message of an Invalid password!

This is the url in which I have uploaded the php page.

http://localhost/test/index.php?password=test













http://localhost/test/index.php?password=somepass123












So now we just have to connect our vb.net application to that url, ok first things first we open our VB.NET IDE (I have Microsoft Visual Basic 2008 Express Edition) but any version with VB.NET would do just fine.

We make a new Console application and paste this code inside it.

Module Module1
    Sub Main()
        Dim remoteURL As String = "http://localhost/test/"
        Dim page As String = "index.php"
        Dim parameter As String = "?password="
        Dim password As String = String.Empty
        While (password = String.Empty)
            Console.WriteLine("Please enter your password:")
            password = Console.ReadLine
        End While
        Dim C As New System.Net.WebClient
        Dim remoteOutput As String = C.DownloadString(remoteURL & page & parameter & password)
        MsgBox(remoteOutput)
    End Sub
End Module

Well this is pretty self-explainable, we have our url and parameter and etc..
We just read a password from the user and then we use it as the parameter value on our php website and then we get the output from the website using a WebClient class, after that we just show the output to the user and we are done! Hope it was easy!



Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου