PHP Programming - Post Request from C# code to PHP
Here is the C# sample code that makes a HTTP post request to a php page.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using System.Net;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string URL = "http://www.softwareandfinance.com/PHP/portal_welcome.php";
WebClient webClient = new WebClient();
NameValueCollection formData = new NameValueCollection();
formData["username"] = "testuser";
formData["password"] = "mypassword";
byte[] responseBytes = webClient.UploadValues(URL, "POST", formData);
string responsefromserver = Encoding.UTF8.GetString(responseBytes);
Console.WriteLine(responsefromserver);
webClient.Dispose();
}
}
}
The code for "portal_welcome.php" is given below:
// multiple ';
?>
You password is: .
The above code can also be written as,
';
echo '
';
echo "You password is: ";
echo $_POST["password"];
?>
|
|