tags:

views:

322

answers:

2

hi,

i have big problem in posting data to php (because im newbie in c# )

ok

i want send this request to server

string Parameters = "hwid=" + _serialNo + "&country=" + PcIp + "&nat=1&pcname=" + PcName + "&winver=" + str;

and after sending data to server get activation key ,

in my server side i used simple php + mysql get Parameters , check it , then show me code this code check user

if (mysql_query($sql)) {echo "done1";
   } else {echo "err211";}

if c# program get done1 , get this code

$sql = "SELECT `key` FROM `clients` WHERE `hwid` = '".dRead("hwid")."';";
       $res = mysql_query($sql);
       echo mysql_result($res, 0);

and if c# program get key , start working

ok where is my problem ?

i cant write program for sending data , i read many blog but none of them explain me who to POST data , and get response :(

so please some one teach me ,

+1  A: 

HttpWebRequest allows you to set the verb in the request

HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://host/page.php?"+Parameters);
myRequest.Method = "POST";

If you're not sending any other data, then you should just be able to call myRequest.GetResponse and read the results from that.

Steve Gilham
A: 

simply, WebClient.UploadValues:

    NameValueCollection fields = new NameValueCollection();
    fields.Add("a","b");
    fields.Add("c","d");
    using (var client = new WebClient())
    {
        byte[] resp = client.UploadValues(address, fields);
        // use Encoding to get resp as a string if needed
    }
Marc Gravell