1

How can I pass some data to a webpage from C#.net? I'm currently using this:

ProcessStartInfo p1 = new ProcessStartInfo("http://www.example.com","key=123");
Process.Start(p1);

but how can I access it from PHP? I tried:

<?php echo($_GET['key']); ?> 

but it prints nothing.

aarti
  • 175
  • 2
  • 15

4 Answers4

1

Try passing it with the url itself

ProcessStartInfo p1 = new ProcessStartInfo("http://timepass.comule.com?key=123","");  
Process.Start(p1);
Muthu
  • 2,675
  • 4
  • 28
  • 34
  • Don't forget to escape the URL variable if it's not going to be as clean as 123 (e.g. user text input) – jocull Oct 18 '11 at 02:51
  • i am actully sending product key.i don't want to pass product key as query string,not even in encrypted format. – aarti Oct 18 '11 at 02:59
  • I am not sure if you have a way of passing data to your web server through a web url without using GET or POST parameters. Instead you can try using Web services with WSDL files over SSL. Or you can just make this particular url SSL. But it still passes the url in an encrypted format. – Muthu Oct 18 '11 at 03:04
  • it means the encrypted key will be displayed in URl,if i use what you say..? – aarti Oct 18 '11 at 03:17
  • Yep, but with SSL the values are not reversible. If you are not able to implement SSL, you can implement some encryption algorithms and decrypt at the other end. – Muthu Oct 18 '11 at 03:27
  • but as i said :i am actully sending product key.i don't want to pass product key as query string,not even in encrypted format – aarti Oct 18 '11 at 03:50
1

you should put the key parameter as a query string :

ProcessStartInfo p1 = new ProcessStartInfo("http://timepass.comule.com?key=123");
ojlovecd
  • 4,812
  • 1
  • 20
  • 22
1

I would suggest using the HttpWebRequestClass.

http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx

This way, you would also have the ability to post data to your page, add auth parameters, cookies etc - in case you might need it.

I'm not sure if this matters in your particular setup, passing data thru the query string is not secure. But if security is an issue as well, I would POST the data thru an SSL connection.

Update:

so if you POST'ed data to your php page like so:

string dataToSend = "data=" + HttpUtility.UrlEncode("this is your data string");
var dataBytes = System.Text.Encoding.UTF8.GetBytes(dataToSend);

HttpWebRequest req = (HttpWebRequest) WebRequest.Create("http://localhost/yourpage.php");
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = dataBytes.Length;
req.Method = "POST";

using (var stream = req.GetRequestStream())
{
    stream.Write(dataBytes, 0, dataBytes.Length);
}

// -- execute request and get response
HttpWebResponse resp = (HttpWebResponse) req.GetResponse();
if (resp.StatusCode == HttpStatusCode.OK)
    Console.WriteLine("Hooray!");

you can retrieve it by using the following code in your php page:

echo $_POST["data"]) 

Update 2:

AFAIK, ProcessStartInfo/Process.Start() actually starts a process - in this case, I think it will start your browser. The second parameter is the command line arguments. This information is used by programs so they know how to behave when started (hidden, open a default document etc). Its not related to the Query string in anyway. if you prefer to use Process.Start(), then try something like this:

ProcessStartInfo p1 = new ProcessStartInfo("iexplore","http://google.com?q=test");
Process.Start(p1); 

If you run that, it will open internet explorer and open google with test on the search box. If that were you're page, you could access "q" by calling:

echo $_GET["q"]) 
Mel
  • 3,058
  • 4
  • 26
  • 40
0

In my applications i used different method i.e using webClient i done it

WebClient client1 = new WebClient();
string path = "dtscompleted.php";//your php path
NameValueCollection formData = new NameValueCollection();
byte[] responseBytes2=null;
formData.Add("key", "123");
try
 {
      responseBytes2 = client1.UploadValues(path, "POST", formData);
 }
catch (WebException web)
 {
      //MessageBox.Show("Check network connection.\n"+web.Message);
 }
deepi
  • 1,081
  • 10
  • 18