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.

1
  • What does <?php echo $_REQUEST['key']; ?> give you? Commented Oct 18, 2011 at 2:50

4 Answers 4

1

Try passing it with the url itself

ProcessStartInfo p1 = new ProcessStartInfo("http://timepass.comule.com?key=123","");  
Process.Start(p1);
Sign up to request clarification or add additional context in comments.

6 Comments

Don't forget to escape the URL variable if it's not going to be as clean as 123 (e.g. user text input)
i am actully sending product key.i don't want to pass product key as query string,not even in encrypted format.
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.
it means the encrypted key will be displayed in URl,if i use what you say..?
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.
|
1

you should put the key parameter as a query string :

ProcessStartInfo p1 = new ProcessStartInfo("http://timepass.comule.com?key=123");

Comments

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"]) 

2 Comments

i don't want to use querystring because it will be displayed in url when webpage opens,i may use encrypted format but yet not.
then your best bet is to use post data
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);
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.