So I thought it's time for me to learn C#, be easy with me guys, I'm very new to this.
I'm trying to create a very simple application (I'm using Windows Forms Application). My goal is:
- Using "GET" method, get the web page
- Read a text field (this value changes every time that the user is accessing the page
- Using "POST" method, send some values accordingly
Here is my code so far:
private void button2_Click(object sender, EventArgs e)
{
string URI = "http://localhost/post.php";
string myParameters = "field=value1&field2=value2";
using (WebClient wc = new WebClient())
{
string getpage = wc.DownloadString("http://localhost/post.php");
MessageBox.Show(getpage);
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
string HtmlResult = wc.UploadString(URI, myParameters);
MessageBox.Show(HtmlResult);
}
}
So far so good, It's working but it's not entirely what I want to achieve here. I'm able to use POST method, but how do I use GET before sending the data? I want to send data according to GET result.
Please let me know if I should be giving a better description to what I'm trying to do.
Thanks.
Edit
This is my PHP Code:
<?php
$a = session_id();
if(empty($a))
session_start();
echo "Session: ".session_id()."<br/>\n";
Now, back to my C# code, I get different session ID in the two messages